Skip to content

fix: alter column uppercase type #154

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

Merged
merged 5 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ None. Please don't use this as a standalone server. This should be used behind a

## Developers

1. Start the database using `docker-compose -f test/db/docker-compose.yml up`.
2. Run `npm run dev`.
3. Run `npm test` while you work.
To start developing, run `npm run dev`. It will set up the database with Docker for you. The server will restart on file change.

If you are fixing a bug, you should create a new test case. To test your changes, add the `-u/--updateSnapshot` flag to `jest` on the `test:run` script, run `npm run test`, and then review the git diff of the snapshots. Depending on your change, you may see `id` fields being changed - this is expected and you are free to commit it, as long as it passes the CI. Don't forget to remove the `-u/--updateSnapshot` flag when committing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soedirgo we should use Property matchers if the id is changing and we don't care. We shouldn't recommend doing updateSnapshot because it will too easily introduce regression

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've started using it on newer tests - I deferred using it when I did the Jest migration because it was a pain to apply for all cases (some id are nested in objects in arrays - need preprocessing there). I'll create an issue to use property matchers on existing tests.

For now I think it's ok to temporarily keep ids and use --updateSnapshot.


## Licence

Expand Down
2 changes: 1 addition & 1 deletion src/lib/PostgresMetaColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ COMMIT;`
? ''
: `ALTER TABLE ${ident(old!.schema)}.${ident(old!.table)} ALTER COLUMN ${ident(
old!.name
)} SET DATA TYPE ${type} USING ${ident(old!.name)}::${type};`
)} SET DATA TYPE ${ident(type)} USING ${ident(old!.name)}::${ident(type)};`

let defaultValueSql: string
if (drop_default) {
Expand Down
48 changes: 48 additions & 0 deletions test/lib/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,51 @@ Object {

await pgMeta.tables.remove(testTable!.id)
})

// https://github.com/supabase/supabase/issues/3553
test('alter column to type with uppercase', async () => {
const { data: testTable } = await pgMeta.tables.create({ name: 't' })
await pgMeta.query('CREATE TYPE "T" AS ENUM ()')

let res = await pgMeta.columns.create({
table_id: testTable!.id,
name: 'c',
type: 'text',
is_unique: false,
})
res = await pgMeta.columns.update(res.data!.id, { type: 'T' })
expect(res).toMatchInlineSnapshot(
{
data: {
id: expect.stringMatching(/^\d+\.\d+$/),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you already have a property matcher? any reason for the comment above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered above #154 (comment)

table_id: expect.any(Number),
},
},
`
Object {
"data": Object {
"comment": null,
"data_type": "USER-DEFINED",
"default_value": null,
"enums": Array [],
"format": "T",
"id": StringMatching /\\^\\\\d\\+\\\\\\.\\\\d\\+\\$/,
"identity_generation": null,
"is_identity": false,
"is_nullable": true,
"is_unique": false,
"is_updatable": true,
"name": "c",
"ordinal_position": 1,
"schema": "public",
"table": "t",
"table_id": Any<Number>,
},
"error": null,
}
`
)

await pgMeta.tables.remove(testTable!.id)
await pgMeta.query('DROP TYPE "T"')
})
8 changes: 4 additions & 4 deletions test/lib/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Object {
"check": null,
"command": "ALL",
"definition": null,
"id": 16663,
"id": 16674,
"name": "test policy",
"roles": Array [
"public",
Expand All @@ -59,7 +59,7 @@ Object {
"check": null,
"command": "ALL",
"definition": null,
"id": 16663,
"id": 16674,
"name": "test policy",
"roles": Array [
"public",
Expand All @@ -83,7 +83,7 @@ Object {
"check": "(current_setting('my.username'::text) = name)",
"command": "ALL",
"definition": "(current_setting('my.username'::text) = name)",
"id": 16663,
"id": 16674,
"name": "policy updated",
"roles": Array [
"public",
Expand All @@ -103,7 +103,7 @@ Object {
"check": "(current_setting('my.username'::text) = name)",
"command": "ALL",
"definition": "(current_setting('my.username'::text) = name)",
"id": 16663,
"id": 16674,
"name": "policy updated",
"roles": Array [
"public",
Expand Down
18 changes: 9 additions & 9 deletions test/lib/publications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('retrieve, create, update, delete', async () => {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16664,
"id": 16675,
"name": "a",
"owner": "postgres",
"publish_delete": true,
Expand All @@ -34,7 +34,7 @@ Object {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16664,
"id": 16675,
"name": "a",
"owner": "postgres",
"publish_delete": true,
Expand All @@ -60,7 +60,7 @@ Object {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16664,
"id": 16675,
"name": "b",
"owner": "postgres",
"publish_delete": true,
Expand All @@ -76,7 +76,7 @@ Object {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16664,
"id": 16675,
"name": "b",
"owner": "postgres",
"publish_delete": true,
Expand Down Expand Up @@ -109,7 +109,7 @@ test('tables with uppercase', async () => {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16669,
"id": 16680,
"name": "pub",
"owner": "postgres",
"publish_delete": false,
Expand All @@ -118,7 +118,7 @@ Object {
"publish_update": false,
"tables": Array [
Object {
"id": 16666,
"id": 16677,
"name": "T",
"schema": "public",
},
Expand All @@ -133,7 +133,7 @@ Object {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16669,
"id": 16680,
"name": "pub",
"owner": "postgres",
"publish_delete": false,
Expand All @@ -142,7 +142,7 @@ Object {
"publish_update": false,
"tables": Array [
Object {
"id": 16666,
"id": 16677,
"name": "T",
"schema": "public",
},
Expand All @@ -167,7 +167,7 @@ test('FOR ALL TABLES', async () => {
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
"id": 16671,
"id": 16682,
"name": "for_all",
"owner": "postgres",
"publish_delete": true,
Expand Down
8 changes: 4 additions & 4 deletions test/lib/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Object {
"can_login": true,
"config": null,
"connection_limit": 100,
"id": 16661,
"id": 16672,
"inherit_role": false,
"is_replication_role": true,
"is_superuser": true,
Expand All @@ -424,7 +424,7 @@ Object {
"can_login": true,
"config": null,
"connection_limit": 100,
"id": 16661,
"id": 16672,
"inherit_role": false,
"is_replication_role": true,
"is_superuser": true,
Expand Down Expand Up @@ -461,7 +461,7 @@ Object {
"can_login": true,
"config": null,
"connection_limit": 100,
"id": 16662,
"id": 16673,
"inherit_role": false,
"is_replication_role": true,
"is_superuser": true,
Expand All @@ -483,7 +483,7 @@ Object {
"can_login": true,
"config": null,
"connection_limit": 100,
"id": 16662,
"id": 16673,
"inherit_role": false,
"is_replication_role": true,
"is_superuser": true,
Expand Down
12 changes: 6 additions & 6 deletions test/lib/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Object {
],
"function_name": "audit_action",
"function_schema": "public",
"id": 16672,
"id": 16683,
"name": "test_trigger",
"orientation": "ROW",
"schema": "public",
Expand All @@ -54,7 +54,7 @@ Object {
],
"function_name": "audit_action",
"function_schema": "public",
"id": 16672,
"id": 16683,
"name": "test_trigger",
"orientation": "ROW",
"schema": "public",
Expand Down Expand Up @@ -83,7 +83,7 @@ Object {
],
"function_name": "audit_action",
"function_schema": "public",
"id": 16672,
"id": 16683,
"name": "test_trigger_renamed",
"orientation": "ROW",
"schema": "public",
Expand Down Expand Up @@ -111,7 +111,7 @@ Object {
],
"function_name": "audit_action",
"function_schema": "public",
"id": 16672,
"id": 16683,
"name": "test_trigger_renamed",
"orientation": "ROW",
"schema": "public",
Expand All @@ -137,7 +137,7 @@ Object {
],
"function_name": "audit_action",
"function_schema": "public",
"id": 16672,
"id": 16683,
"name": "test_trigger_renamed",
"orientation": "ROW",
"schema": "public",
Expand Down Expand Up @@ -186,7 +186,7 @@ Object {
],
"function_name": "audit_action",
"function_schema": "public",
"id": 16673,
"id": 16684,
"name": "test_multi_event_trigger",
"orientation": "ROW",
"schema": "public",
Expand Down