Skip to content

Commit fe6af73

Browse files
committed
feat: persist turf to db
1 parent 5ce2481 commit fe6af73

20 files changed

Lines changed: 506 additions & 126 deletions

File tree

migrations/1751382607271_placed_marker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Kysely, sql } from "kysely";
44
export async function up(db: Kysely<any>): Promise<void> {
55
await db.schema
66
.createTable("placedMarker")
7-
.addColumn("id", "bigserial", (col) => col.notNull())
7+
.addColumn("id", "bigserial", (col) => col.primaryKey())
88
.addColumn("mapId", "uuid", (col) => col.notNull())
99
.addColumn("label", "text", (col) => col.notNull())
1010
.addColumn("notes", "text", (col) => col.notNull().defaultTo(""))

migrations/1751470125413_turf.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { Kysely, sql } from "kysely";
3+
4+
export async function up(db: Kysely<any>): Promise<void> {
5+
await db.schema
6+
.createTable("turf")
7+
.addColumn("id", "uuid", (col) =>
8+
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
9+
)
10+
.addColumn("label", "text", (col) => col.notNull())
11+
.addColumn("notes", "text", (col) => col.notNull().defaultTo(""))
12+
.addColumn("area", sql`double precision`, (col) => col.notNull())
13+
.addColumn("geometry", "jsonb", (col) => col.notNull())
14+
.addColumn("createdAt", sql`TIMESTAMP`, (col) =>
15+
col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull(),
16+
)
17+
.addColumn("mapId", "uuid", (col) => col.notNull())
18+
.addForeignKeyConstraint("turfMapIdFKey", ["mapId"], "map", ["id"], (cb) =>
19+
cb.onDelete("cascade").onUpdate("cascade"),
20+
)
21+
.execute();
22+
}
23+
24+
export async function down(db: Kysely<any>): Promise<void> {
25+
await db.schema.dropTable("turf").execute();
26+
}

src/__generated__/types.ts

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)