Skip to content

Commit 6ea21ab

Browse files
committed
chore: update column types
1 parent 53a2b12 commit 6ea21ab

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Kysely, sql } from "kysely";
2+
3+
export async function up(db: Kysely<any>): Promise<void> {
4+
await db.schema
5+
.alterTable("vot_translations")
6+
.alterColumn("id", (col) => col.dropDefault())
7+
.alterColumn("id", (col) => col.setDataType("bigint"))
8+
.alterColumn("created_at", (col) => col.setDataType("timestamptz"))
9+
.execute();
10+
11+
await sql`DROP SEQUENCE public.vot_translations_id_seq CASCADE`.execute(db);
12+
13+
await sql`ALTER TABLE vot_translations DROP CONSTRAINT IF EXISTS vot_translations_pkey`.execute(
14+
db,
15+
);
16+
await sql`ALTER TABLE vot_translations ALTER id ADD GENERATED ALWAYS AS IDENTITY`.execute(db);
17+
await sql`SELECT setval(pg_get_serial_sequence('vot_translations', 'id'), max(id)) FROM vot_translations;`.execute(
18+
db,
19+
);
20+
}
21+
22+
export async function down(db: Kysely<any>): Promise<void> {
23+
await db.schema
24+
.alterTable("vot_translations")
25+
.alterColumn("id", (col) => col.setDataType("serial"))
26+
.alterColumn("created_at", (col) => col.setDataType("timestamp"))
27+
.execute();
28+
29+
await sql`ALTER TABLE vot_translations ADD CONSTRAINT vot_translations_pkey PRIMARY KEY ("id");`.execute(
30+
db,
31+
);
32+
}

0 commit comments

Comments
 (0)