Skip to content

[Backend] ensure-core-tables migration CREATE TABLE loan_events collides with the loan_events compatibility view, breaking a clean migration apply #1099

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

Migration order by timestamp: 1788000000018_unified-contract-events.js renames the loan_events table to contract_events and creates a VIEW named loan_events (lines 7,52-69). The next migration 1789000000000_ensure-core-tables.js:31-37 guards with IF NOT EXISTS (SELECT FROM pg_tables WHERE tablename='loan_events') THEN CREATE TABLE loan_events (...). pg_tables only lists ordinary tables (relkind r/p) and excludes views, so the guard evaluates TRUE and runs CREATE TABLE loan_events, which fails with relation loan_events already exists because the view occupies that name. On any from-scratch sequential migration the run aborts.

Acceptance criteria

  • Detect the relation via pg_class / information_schema.tables (which include views) or use to_regclass('loan_events') instead of pg_tables
  • Make the CREATE TABLE branch a no-op when loan_events already exists as a view
  • Add a CI step that runs the full migration set against an empty database

Files to touch

  • backend/migrations/1789000000000_ensure-core-tables.js
  • backend/migrations/1788000000018_unified-contract-events.js

Out of scope

  • Scores column rename runtime mismatch (already filed)
  • Indexer inserting into the view (already filed)

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendIssues related to backend developmentbugSomething isn't workingcriticalHigh-impact / hard issuedatabaseDatabase related issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions