-
Notifications
You must be signed in to change notification settings - Fork 85
db-migrations: use pg for new migrations #1363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alxndrsn
wants to merge
145
commits into
getodk:master
Choose a base branch
from
alxndrsn:prevent-new-migrations-with-knex
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 22 commits
Commits
Show all changes
145 commits
Select commit
Hold shift + click to select a range
5afe783
wip: replace knex for new database migrations
7a0260d
move all the migrations; implement the migrator
2d9ff15
Add db migration test from other PR
42023e0
fix imports; lints
c838cf6
Add eslint rules
a9aea26
whitespace
609c34c
rename withDatabase()
c2ce4ba
lint?
714985f
make sure client closed
72bb6b0
add comment
65e7709
await
2fceecf
handle connection closing
2e42824
run migrations in tests another way
0821bdd
rename knexConnection in line with master changes
ae64408
Merge branch 'master' into prevent-new-migrations-with-knex
100c424
Change in line with #1371
bb0d883
js -> json
e2d64cc
reduce changes by renaming migration dirs
de1e5d7
Add TODOs
887c492
remove lint changes to legacy migrations
ed41ada
revert debug
0769356
revert knexConfig name change
71d4a8c
Merge branch 'master' into prevent-new-migrations-with-knex
c95cec6
renames to be less knexy
322c5ba
reduce changeset
6c1a62b
revert whitespace change
a415a70
import fixes for null content types
5d6218b
import query changes
fafc6fb
e2e test fix?
8c6cf29
import test changes
b264a83
ci/db-migrations: add new path
9a1db56
Make migration tests pass?
9987704
only move js?
f20dad4
lint
8aa2286
wip
62f043d
add migrator name
ec35f7c
correct arg count
f20e9a1
Merge branch 'master' into prevent-new-migrations-with-knex
alxndrsn 1acb27c
Merge branch 'master' into prevent-new-migrations-with-knex
08f235c
add check
3f8aa12
rename new migration
26fe2ea
Fix test migrator
2d015c8
update
b21b486
remove logging
4c5ce3a
remove superseded migration
a15fe02
lint
b78683d
reintroduce faster migration
8b3b4db
Add review query
ee46a00
Merge branch 'master' into prevent-new-migrations-with-knex
b44e674
Resolve TODO
cf5a4fd
spelling
5dc4df6
Use same migrations table
9d0335f
revert name change for describeMigration()
5336ac9
fix knex_migrations table updates
86082d4
lint
d276085
ignore missing migrations
5aba8f8
document previous
9393aa4
change migration directories
0cee983
move migrations
244d36c
last migration
dfa2048
rename post-knex
9215950
move eslintrc
7d70054
remove dead file
7f6a8b6
fix requires
6bf53ad
name
c7fa35e
wip
4275829
raw -> query
929a976
fix?
d1802de
remove old TODOs
193f837
rename migrations tests
0c9610b
skip migration tests
de23f43
resolve REVIEW comment
398960f
resolve REVIEW
f908b9e
resolve TODO
38fdb4b
resolve TODO: validate migration names
ed6bb5e
resolve TODO with better comments
de06080
remove dead comment
1b68d91
Merge branch 'master' into prevent-new-migrations-with-knex
ee1e3f8
new migration: raw -> query
eb14edb
qyer
4414dc4
Merge branch 'master' into prevent-new-migrations-with-knex
176bc73
fix name!
d284918
reduce changeset
0b289d1
fix migration name
7cc1b19
Try removing disableMigrationsListValidation
cd0ff44
Revert "Try removing disableMigrationsListValidation"
e97f81f
expand comment ref disableMigrationsListValidation
1937710
Merge branch 'master' into prevent-new-migrations-with-knex
alxndrsn 80b257c
Merge branch 'master' into prevent-new-migrations-with-knex
alxndrsn 34d57fc
Merge branch 'master' into prevent-new-migrations-with-knex
alxndrsn f219a7b
raw -> query
26583da
build up full matrix
ea9dfcf
ci: add on: section
ef1f0f4
add failing outline of tests
45e4fbe
update and install
b6803ba
without update
14f3650
make executable
a5207d8
wip
5648c47
actually run migrations in the legacy style
6116ba0
more prep
e9ef7d2
wip
332c69b
wip
fbdc6fb
show output
54fbde8
remove js
6fbeb37
wip
4d8da90
test all in one
d50aed3
better cleran
b4b92f1
new filrst
2c7abdd
fix requires in legacy migrations
c4dfd9a
rebuild
efb9ade
build please
2ae8b03
get connection string
c21187a
nicer esxcaping
ba81777
more logging?
7b9acbb
flush output
95b2b14
fix fix
1fccd8b
helpful comments
c1df685
no escape backtick
9f2f4b0
add missing schema file
18ef0e1
expect table contnets
962c6a8
ye
f984324
revert some legacy to legacy
514d180
partial
201515a
try different syntax for JSONB_EXISTS
19c8ead
Revert "revert some legacy to legacy"
c63e4fa
Revert "partial"
b82c47e
add missing pgConnectionString
757bb93
tryail
edfc3fc
add expected schema
7f3ca0f
add trailing newline?
de3db3c
select less cols
c0dd6e6
flushings
083b604
expected table contents
6fd9531
trailing newline
1a7d8a7
remove x
30b71b5
remove random output in the middle
ff0a10d
disable knex debug
a7b4edd
Merge branch 'master' into prevent-new-migrations-with-knex
alxndrsn 0271b3a
check half way
0391aff
wip
77d8d62
just print name
8048910
prefixes
9b95483
js only
6089fbf
sort
df96dbc
Merge branch 'master' into prevent-new-migrations-with-knex
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "extends": "../../../.eslintrc.json", | ||
| "rules": { | ||
| "no-restricted-modules": [ "error", { "patterns": [ "../*" ] } ] | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
lib/model/migrations-post-knex/20250113-01-disable-nullable-blob-content-types.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright 2025 ODK Central Developers | ||
| // See the NOTICE file at the top-level directory of this distribution and at | ||
| // https://github.com/getodk/central-backend/blob/master/NOTICE. | ||
| // This file is part of ODK Central. It is subject to the license terms in | ||
| // the LICENSE file found in the top-level directory of this distribution and at | ||
| // https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||
| // including this file, may be copied, modified, propagated, or distributed | ||
| // except according to the terms contained in the LICENSE file. | ||
|
|
||
| const up = (db) => db.query(` | ||
| ALTER TABLE blobs | ||
| ALTER COLUMN "contentType" TYPE TEXT USING(COALESCE("contentType", 'application/octet-stream')), | ||
| ALTER COLUMN "contentType" SET DEFAULT 'application/octet-stream', | ||
| ALTER COLUMN "contentType" SET NOT NULL | ||
| `); | ||
|
|
||
| const down = (db) => db.query(` | ||
| ALTER TABLE blobs | ||
| ALTER COLUMN "contentType" DROP NOT NULL, | ||
| ALTER COLUMN "contentType" DROP DEFAULT | ||
| `); | ||
|
|
||
| module.exports = { up, down }; |
58 changes: 58 additions & 0 deletions
58
test/db-migrations/20250113-01-disable-nullable-blob-content-types.spec.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| const assert = require('node:assert/strict'); | ||
| const { hash, randomBytes } = require('node:crypto'); | ||
|
|
||
| const { // eslint-disable-line object-curly-newline | ||
| assertTableContents, | ||
| describeMigration, | ||
| rowsExistFor, | ||
| } = require('./utils'); // eslint-disable-line object-curly-newline | ||
|
|
||
| describeMigration('20250113-01-disable-nullable-blob-content-types', ({ runMigrationBeingTested }) => { | ||
| const aBlobWith = props => { | ||
| const randomContent = randomBytes(100); | ||
| const md5 = hash('md5', randomContent); // eslint-disable-line no-multi-spaces | ||
| const sha = hash('sha1', randomContent); | ||
| return { md5, sha, ...props }; | ||
| }; | ||
| const aBlob = () => aBlobWith({}); | ||
|
|
||
| const blob1 = aBlobWith({ contentType: null }); | ||
| const blob2 = aBlobWith({ contentType: 'text/plain' }); | ||
|
|
||
| before(async () => { | ||
| await rowsExistFor('blobs', blob1, blob2); | ||
|
|
||
| await runMigrationBeingTested(); | ||
| }); | ||
|
|
||
| it('should change existing NULL contentType values to application/octet-stream, and preserve non-NULL values', async () => { | ||
| await assertTableContents('blobs', | ||
| { ...blob1, contentType: 'application/octet-stream' }, | ||
| { ...blob2, contentType: 'text/plain' }, | ||
| ); | ||
| }); | ||
|
|
||
| it(`should create new blobs with contentType 'application/octet-stream' (contentType not supplied)`, async () => { | ||
| const { md5, sha } = aBlob(); | ||
|
|
||
| const created = await db.oneFirst(sql` | ||
| INSERT INTO blobs (md5, sha, "contentType") | ||
| VALUES(${md5}, ${sha}, DEFAULT) | ||
| RETURNING "contentType" | ||
| `); | ||
|
|
||
| assert.equal(created, 'application/octet-stream'); | ||
| }); | ||
|
|
||
| it(`should create new blobs with contentType 'application/octet-stream' (supplied DEFAULT contentType)`, async () => { | ||
| const { md5, sha } = aBlob(); | ||
|
|
||
| const created = await db.oneFirst(sql` | ||
| INSERT INTO blobs (md5, sha, "contentType") | ||
| VALUES(${md5}, ${sha}, DEFAULT) | ||
| RETURNING "contentType" | ||
| `); | ||
|
|
||
| assert.equal(created, 'application/octet-stream'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.