fix(db): drop FKs to removed users table so db:migrate completes#3
Open
gomessguii wants to merge 1 commit intodevelopfrom
Open
fix(db): drop FKs to removed users table so db:migrate completes#3gomessguii wants to merge 1 commit intodevelopfrom
gomessguii wants to merge 1 commit intodevelopfrom
Conversation
Seven migrations still referenced a users table that no longer exists in community (identity now lives in evo-auth-service). db:migrate aborted on the first of them (CreateFacebookCommentModerations), which in turn blocked MakeAttachmentPolymorphic and left attachments stuck with the legacy message_id column. Sidekiq/Puma then crashed with PG::UndefinedColumn: attachments.attachable_id does not exist whenever media or contact deletion touched the table. Replace each FK to :users with a plain uuid column (keeping the same column names so models keep working) plus manual indexes where the auto-generated ones disappeared. Also stop docker-entrypoint.sh from masking boot errors with 2>/dev/null || true — that mask is what hid this abort in the first place. db:evolution_prepare already covers create + schema:load + migrate in one call, so collapse the three-command dance into a single unmasked invocation.
There was a problem hiding this comment.
Sorry @gomessguii, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
userstable that no longer exists in community (removed in9944be0when identity moved toevo-auth-service).db:migrateaborted on the first of them (CreateFacebookCommentModerations), blockingMakeAttachmentPolymorphicand leavingattachmentsstuck with the legacymessage_idcolumn. Sidekiq/Puma then crashed withPG::UndefinedColumn: attachments.attachable_id does not existon any media webhook or contact deletion.foreign_key: { to_table: :users }/add_foreign_key …, :usersswapped for a plainuuidcolumn (same name, so models keep working) plus manual indexes where the auto-generated ones went away.docker/docker-entrypoint.sh: collapsed thedb:create/db:migrate/db:evolution_preparetrio (all masked by2>/dev/null || true) into a single unmaskedbundle exec rails db:evolution_prepare. The mask is what hid the abort in the first place — a broken migration must stop the boot.Root cause
The account/user removal refactor (
9944be0) only toucheddb/schema.rb; the downstream migrations that reference:userswere never scrubbed. Theversion: 9025_08_19_224901bump in that same commit papers over the problem viaassume_migrated_upto_version— it only works on thedb:schema:loadpath. Anydb:migrateon an empty DB still walks the migrations in chronological order and hits the FK abort.Test plan
db:migrateagainst a clean Postgres completes: 51/51 migrations applied, 0 pending.\d attachmentson the resulting DB showsattachable_type/attachable_id(withindex_attachments_on_attachable_type_and_attachable_id) and nomessage_id.schema_migrationscontains20251119155458(the previously-blocked polymorphic migration).MakeAttachmentPolymorphicidempotency (may need a follow-up guard).