diff --git a/README.md b/README.md index 8191aae4..3ac1fb23 100644 --- a/README.md +++ b/README.md @@ -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. ## Licence diff --git a/src/lib/PostgresMetaColumns.ts b/src/lib/PostgresMetaColumns.ts index 7720d643..f1866cfd 100644 --- a/src/lib/PostgresMetaColumns.ts +++ b/src/lib/PostgresMetaColumns.ts @@ -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) { diff --git a/test/lib/columns.ts b/test/lib/columns.ts index 128086df..1cfa5499 100644 --- a/test/lib/columns.ts +++ b/test/lib/columns.ts @@ -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+$/), + 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, + }, + "error": null, + } + ` + ) + + await pgMeta.tables.remove(testTable!.id) + await pgMeta.query('DROP TYPE "T"') +}) diff --git a/test/lib/policies.ts b/test/lib/policies.ts index f3e812b2..ec3cdfc9 100644 --- a/test/lib/policies.ts +++ b/test/lib/policies.ts @@ -39,7 +39,7 @@ Object { "check": null, "command": "ALL", "definition": null, - "id": 16663, + "id": 16674, "name": "test policy", "roles": Array [ "public", @@ -59,7 +59,7 @@ Object { "check": null, "command": "ALL", "definition": null, - "id": 16663, + "id": 16674, "name": "test policy", "roles": Array [ "public", @@ -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", @@ -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", diff --git a/test/lib/publications.ts b/test/lib/publications.ts index eae2c06d..70172cfa 100644 --- a/test/lib/publications.ts +++ b/test/lib/publications.ts @@ -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, @@ -34,7 +34,7 @@ Object { expect(res).toMatchInlineSnapshot(` Object { "data": Object { - "id": 16664, + "id": 16675, "name": "a", "owner": "postgres", "publish_delete": true, @@ -60,7 +60,7 @@ Object { expect(res).toMatchInlineSnapshot(` Object { "data": Object { - "id": 16664, + "id": 16675, "name": "b", "owner": "postgres", "publish_delete": true, @@ -76,7 +76,7 @@ Object { expect(res).toMatchInlineSnapshot(` Object { "data": Object { - "id": 16664, + "id": 16675, "name": "b", "owner": "postgres", "publish_delete": true, @@ -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, @@ -118,7 +118,7 @@ Object { "publish_update": false, "tables": Array [ Object { - "id": 16666, + "id": 16677, "name": "T", "schema": "public", }, @@ -133,7 +133,7 @@ Object { expect(res).toMatchInlineSnapshot(` Object { "data": Object { - "id": 16669, + "id": 16680, "name": "pub", "owner": "postgres", "publish_delete": false, @@ -142,7 +142,7 @@ Object { "publish_update": false, "tables": Array [ Object { - "id": 16666, + "id": 16677, "name": "T", "schema": "public", }, @@ -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, diff --git a/test/lib/roles.ts b/test/lib/roles.ts index ed6f768f..5add99fe 100644 --- a/test/lib/roles.ts +++ b/test/lib/roles.ts @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/test/lib/triggers.ts b/test/lib/triggers.ts index 0c865e67..6b765221 100644 --- a/test/lib/triggers.ts +++ b/test/lib/triggers.ts @@ -28,7 +28,7 @@ Object { ], "function_name": "audit_action", "function_schema": "public", - "id": 16672, + "id": 16683, "name": "test_trigger", "orientation": "ROW", "schema": "public", @@ -54,7 +54,7 @@ Object { ], "function_name": "audit_action", "function_schema": "public", - "id": 16672, + "id": 16683, "name": "test_trigger", "orientation": "ROW", "schema": "public", @@ -83,7 +83,7 @@ Object { ], "function_name": "audit_action", "function_schema": "public", - "id": 16672, + "id": 16683, "name": "test_trigger_renamed", "orientation": "ROW", "schema": "public", @@ -111,7 +111,7 @@ Object { ], "function_name": "audit_action", "function_schema": "public", - "id": 16672, + "id": 16683, "name": "test_trigger_renamed", "orientation": "ROW", "schema": "public", @@ -137,7 +137,7 @@ Object { ], "function_name": "audit_action", "function_schema": "public", - "id": 16672, + "id": 16683, "name": "test_trigger_renamed", "orientation": "ROW", "schema": "public", @@ -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",