yesodweb / yesodweb/persistent
Unnecessary migration when no schema change
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
Persistent tries this migration and fails on existing FOREIGN KEY
Migrating: CREATE TEMP TABLE "user_backup"("id" INTEGER PRIMARY KEY,"stellar_address" VARCHAR NOT NULL,"name" VARCHAR NULL,CONSTRAINT "unique_user" UNIQUE ("stellar_address"))
07/Feb/2022:13:00:39 +0300 [Debug#SQL] CREATE TEMP TABLE "user_backup"("id" INTEGER PRIMARY KEY,"stellar_address" VARCHAR NOT NULL,"name" VARCHAR NULL,CONSTRAINT "unique_user" UNIQUE ("stellar_address")); []
Migrating: INSERT INTO "user_backup"("id","stellar_address","name") SELECT "id","stellar_address","name" FROM "user"
Migrating: DROP TABLE "user"
devel.hs: SQLite3 returned ErrorConstraint while attempting to perform step: FOREIGN KEY constraint failed
but why?
oldSql = "CREATE TABLE \"user\"(\"id\" INTEGER PRIMARY KEY,\"stellar_address\" VARCHAR NOT NULL, \"name\" VARCHAR NULL,CONSTRAINT \"unique_user\" UNIQUE (\"stellar_address\"))"
newSql = "CREATE TABLE \"user\"(\"id\" INTEGER PRIMARY KEY,\"stellar_address\" VARCHAR NOT NULL,\"name\" VARCHAR NULL,CONSTRAINT \"unique_user\" UNIQUE (\"stellar_address\"))"
Yes, Sqlite inserts extra space. Is there a way to normalize SQL schema code got from Sqlite?
How to reproduce: first I created Persist schema without name field, then added it by hand (ALTER TABLE ADD COLUMN) on the production database.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by reproducing the shown oldSql/newSql comparison with the SQLite schema that was altered by hand, then trace Persistent's SQLite migration decision and foreign-key handling. Done means semantically identical schemas do not trigger an unnecessary migration and the existing foreign key remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, sqlite
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100