Skip to content

Commit 7f43572

Browse files
authored
Merge pull request #154 from supabase/fix/alter-column-uppercase-type
fix: alter column uppercase type
2 parents 8cb7fea + c2a4870 commit 7f43572

File tree

7 files changed

+75
-27
lines changed

7 files changed

+75
-27
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ None. Please don't use this as a standalone server. This should be used behind a
9292

9393
## Developers
9494

95-
1. Start the database using `docker-compose -f test/db/docker-compose.yml up`.
96-
2. Run `npm run dev`.
97-
3. Run `npm test` while you work.
95+
To start developing, run `npm run dev`. It will set up the database with Docker for you. The server will restart on file change.
96+
97+
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.
9898

9999
## Licence
100100

src/lib/PostgresMetaColumns.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ COMMIT;`
210210
? ''
211211
: `ALTER TABLE ${ident(old!.schema)}.${ident(old!.table)} ALTER COLUMN ${ident(
212212
old!.name
213-
)} SET DATA TYPE ${type} USING ${ident(old!.name)}::${type};`
213+
)} SET DATA TYPE ${ident(type)} USING ${ident(old!.name)}::${ident(type)};`
214214

215215
let defaultValueSql: string
216216
if (drop_default) {

test/lib/columns.ts

+48
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,51 @@ Object {
479479

480480
await pgMeta.tables.remove(testTable!.id)
481481
})
482+
483+
// https://github.com/supabase/supabase/issues/3553
484+
test('alter column to type with uppercase', async () => {
485+
const { data: testTable } = await pgMeta.tables.create({ name: 't' })
486+
await pgMeta.query('CREATE TYPE "T" AS ENUM ()')
487+
488+
let res = await pgMeta.columns.create({
489+
table_id: testTable!.id,
490+
name: 'c',
491+
type: 'text',
492+
is_unique: false,
493+
})
494+
res = await pgMeta.columns.update(res.data!.id, { type: 'T' })
495+
expect(res).toMatchInlineSnapshot(
496+
{
497+
data: {
498+
id: expect.stringMatching(/^\d+\.\d+$/),
499+
table_id: expect.any(Number),
500+
},
501+
},
502+
`
503+
Object {
504+
"data": Object {
505+
"comment": null,
506+
"data_type": "USER-DEFINED",
507+
"default_value": null,
508+
"enums": Array [],
509+
"format": "T",
510+
"id": StringMatching /\\^\\\\d\\+\\\\\\.\\\\d\\+\\$/,
511+
"identity_generation": null,
512+
"is_identity": false,
513+
"is_nullable": true,
514+
"is_unique": false,
515+
"is_updatable": true,
516+
"name": "c",
517+
"ordinal_position": 1,
518+
"schema": "public",
519+
"table": "t",
520+
"table_id": Any<Number>,
521+
},
522+
"error": null,
523+
}
524+
`
525+
)
526+
527+
await pgMeta.tables.remove(testTable!.id)
528+
await pgMeta.query('DROP TYPE "T"')
529+
})

test/lib/policies.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Object {
3939
"check": null,
4040
"command": "ALL",
4141
"definition": null,
42-
"id": 16663,
42+
"id": 16674,
4343
"name": "test policy",
4444
"roles": Array [
4545
"public",
@@ -59,7 +59,7 @@ Object {
5959
"check": null,
6060
"command": "ALL",
6161
"definition": null,
62-
"id": 16663,
62+
"id": 16674,
6363
"name": "test policy",
6464
"roles": Array [
6565
"public",
@@ -83,7 +83,7 @@ Object {
8383
"check": "(current_setting('my.username'::text) = name)",
8484
"command": "ALL",
8585
"definition": "(current_setting('my.username'::text) = name)",
86-
"id": 16663,
86+
"id": 16674,
8787
"name": "policy updated",
8888
"roles": Array [
8989
"public",
@@ -103,7 +103,7 @@ Object {
103103
"check": "(current_setting('my.username'::text) = name)",
104104
"command": "ALL",
105105
"definition": "(current_setting('my.username'::text) = name)",
106-
"id": 16663,
106+
"id": 16674,
107107
"name": "policy updated",
108108
"roles": Array [
109109
"public",

test/lib/publications.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('retrieve, create, update, delete', async () => {
1212
expect(res).toMatchInlineSnapshot(`
1313
Object {
1414
"data": Object {
15-
"id": 16664,
15+
"id": 16675,
1616
"name": "a",
1717
"owner": "postgres",
1818
"publish_delete": true,
@@ -34,7 +34,7 @@ Object {
3434
expect(res).toMatchInlineSnapshot(`
3535
Object {
3636
"data": Object {
37-
"id": 16664,
37+
"id": 16675,
3838
"name": "a",
3939
"owner": "postgres",
4040
"publish_delete": true,
@@ -60,7 +60,7 @@ Object {
6060
expect(res).toMatchInlineSnapshot(`
6161
Object {
6262
"data": Object {
63-
"id": 16664,
63+
"id": 16675,
6464
"name": "b",
6565
"owner": "postgres",
6666
"publish_delete": true,
@@ -76,7 +76,7 @@ Object {
7676
expect(res).toMatchInlineSnapshot(`
7777
Object {
7878
"data": Object {
79-
"id": 16664,
79+
"id": 16675,
8080
"name": "b",
8181
"owner": "postgres",
8282
"publish_delete": true,
@@ -109,7 +109,7 @@ test('tables with uppercase', async () => {
109109
expect(res).toMatchInlineSnapshot(`
110110
Object {
111111
"data": Object {
112-
"id": 16669,
112+
"id": 16680,
113113
"name": "pub",
114114
"owner": "postgres",
115115
"publish_delete": false,
@@ -118,7 +118,7 @@ Object {
118118
"publish_update": false,
119119
"tables": Array [
120120
Object {
121-
"id": 16666,
121+
"id": 16677,
122122
"name": "T",
123123
"schema": "public",
124124
},
@@ -133,7 +133,7 @@ Object {
133133
expect(res).toMatchInlineSnapshot(`
134134
Object {
135135
"data": Object {
136-
"id": 16669,
136+
"id": 16680,
137137
"name": "pub",
138138
"owner": "postgres",
139139
"publish_delete": false,
@@ -142,7 +142,7 @@ Object {
142142
"publish_update": false,
143143
"tables": Array [
144144
Object {
145-
"id": 16666,
145+
"id": 16677,
146146
"name": "T",
147147
"schema": "public",
148148
},
@@ -167,7 +167,7 @@ test('FOR ALL TABLES', async () => {
167167
expect(res).toMatchInlineSnapshot(`
168168
Object {
169169
"data": Object {
170-
"id": 16671,
170+
"id": 16682,
171171
"name": "for_all",
172172
"owner": "postgres",
173173
"publish_delete": true,

test/lib/roles.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ Object {
402402
"can_login": true,
403403
"config": null,
404404
"connection_limit": 100,
405-
"id": 16661,
405+
"id": 16672,
406406
"inherit_role": false,
407407
"is_replication_role": true,
408408
"is_superuser": true,
@@ -424,7 +424,7 @@ Object {
424424
"can_login": true,
425425
"config": null,
426426
"connection_limit": 100,
427-
"id": 16661,
427+
"id": 16672,
428428
"inherit_role": false,
429429
"is_replication_role": true,
430430
"is_superuser": true,
@@ -461,7 +461,7 @@ Object {
461461
"can_login": true,
462462
"config": null,
463463
"connection_limit": 100,
464-
"id": 16662,
464+
"id": 16673,
465465
"inherit_role": false,
466466
"is_replication_role": true,
467467
"is_superuser": true,
@@ -483,7 +483,7 @@ Object {
483483
"can_login": true,
484484
"config": null,
485485
"connection_limit": 100,
486-
"id": 16662,
486+
"id": 16673,
487487
"inherit_role": false,
488488
"is_replication_role": true,
489489
"is_superuser": true,

test/lib/triggers.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Object {
2828
],
2929
"function_name": "audit_action",
3030
"function_schema": "public",
31-
"id": 16672,
31+
"id": 16683,
3232
"name": "test_trigger",
3333
"orientation": "ROW",
3434
"schema": "public",
@@ -54,7 +54,7 @@ Object {
5454
],
5555
"function_name": "audit_action",
5656
"function_schema": "public",
57-
"id": 16672,
57+
"id": 16683,
5858
"name": "test_trigger",
5959
"orientation": "ROW",
6060
"schema": "public",
@@ -83,7 +83,7 @@ Object {
8383
],
8484
"function_name": "audit_action",
8585
"function_schema": "public",
86-
"id": 16672,
86+
"id": 16683,
8787
"name": "test_trigger_renamed",
8888
"orientation": "ROW",
8989
"schema": "public",
@@ -111,7 +111,7 @@ Object {
111111
],
112112
"function_name": "audit_action",
113113
"function_schema": "public",
114-
"id": 16672,
114+
"id": 16683,
115115
"name": "test_trigger_renamed",
116116
"orientation": "ROW",
117117
"schema": "public",
@@ -137,7 +137,7 @@ Object {
137137
],
138138
"function_name": "audit_action",
139139
"function_schema": "public",
140-
"id": 16672,
140+
"id": 16683,
141141
"name": "test_trigger_renamed",
142142
"orientation": "ROW",
143143
"schema": "public",
@@ -186,7 +186,7 @@ Object {
186186
],
187187
"function_name": "audit_action",
188188
"function_schema": "public",
189-
"id": 16673,
189+
"id": 16684,
190190
"name": "test_multi_event_trigger",
191191
"orientation": "ROW",
192192
"schema": "public",

0 commit comments

Comments
 (0)