feat: Add DB migrations
This commit is contained in:
parent
878fdc7fb4
commit
3621cf6ae2
4 changed files with 163 additions and 0 deletions
17
drizzle/0000_low_firebird.sql
Normal file
17
drizzle/0000_low_firebird.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
CREATE TABLE `eventsTable` (
|
||||
`id` integer PRIMARY KEY NOT NULL,
|
||||
`startTime` text NOT NULL,
|
||||
`endTime` text NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`title` text NOT NULL,
|
||||
`description` text NOT NULL,
|
||||
`type` text NOT NULL,
|
||||
`lineId` integer NOT NULL,
|
||||
FOREIGN KEY (`lineId`) REFERENCES `linesTable`(`id`) ON UPDATE cascade ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `linesTable` (
|
||||
`id` integer PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`description` text NOT NULL
|
||||
);
|
||||
129
drizzle/meta/0000_snapshot.json
Normal file
129
drizzle/meta/0000_snapshot.json
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "67a86f93-2bc8-4fe2-8786-995874bf9863",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"eventsTable": {
|
||||
"name": "eventsTable",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"startTime": {
|
||||
"name": "startTime",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"endTime": {
|
||||
"name": "endTime",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"lineId": {
|
||||
"name": "lineId",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"eventsTable_lineId_linesTable_id_fk": {
|
||||
"name": "eventsTable_lineId_linesTable_id_fk",
|
||||
"tableFrom": "eventsTable",
|
||||
"tableTo": "linesTable",
|
||||
"columnsFrom": [
|
||||
"lineId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "cascade"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"linesTable": {
|
||||
"name": "linesTable",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
13
drizzle/meta/_journal.json
Normal file
13
drizzle/meta/_journal.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"version": "7",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1750781935205,
|
||||
"tag": "0000_low_firebird",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import type { Event, Line } from "@/common/parser";
|
|||
import "dotenv/config";
|
||||
import { and, eq, gte, inArray, like, lte, or } from "drizzle-orm";
|
||||
import { drizzle } from "drizzle-orm/libsql";
|
||||
import { migrate } from "drizzle-orm/libsql/migrator";
|
||||
import {
|
||||
eventsTable,
|
||||
type eventsTableSelectSchema,
|
||||
|
|
@ -13,6 +14,9 @@ if (!process.env.DB_FILE_NAME) {
|
|||
}
|
||||
|
||||
const db = drizzle(process.env.DB_FILE_NAME);
|
||||
await migrate(db, {
|
||||
migrationsFolder: "./drizzle",
|
||||
});
|
||||
|
||||
export async function saveLines(lines: Line[]) {
|
||||
await db
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue