From fe18eb479f16b56dd3c710d55ec9ba8ee73b96e3 Mon Sep 17 00:00:00 2001 From: Stefan VDV Date: Wed, 30 Apr 2025 15:41:37 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=A7=20Test=20what=20happens=20?= =?UTF-8?q?with=20a=20DB=20change=20is=20made=20in=20a=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a temporary commit, this PR is expected to be closed and not merged --- .../db/migrations/0001_needy_butterfly.sql | 11 + .../db/migrations/meta/0001_snapshot.json | 355 ++++++++++++++++++ src/server/db/migrations/meta/_journal.json | 7 + src/server/db/schema.ts | 42 +-- 4 files changed, 394 insertions(+), 21 deletions(-) create mode 100644 src/server/db/migrations/0001_needy_butterfly.sql create mode 100644 src/server/db/migrations/meta/0001_snapshot.json diff --git a/src/server/db/migrations/0001_needy_butterfly.sql b/src/server/db/migrations/0001_needy_butterfly.sql new file mode 100644 index 0000000..b6a3f3b --- /dev/null +++ b/src/server/db/migrations/0001_needy_butterfly.sql @@ -0,0 +1,11 @@ +CREATE TABLE `mcc-gadgets_tempPost` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text(256), + `created_by` text(255) NOT NULL, + `created_at` integer DEFAULT (unixepoch()) NOT NULL, + `updated_at` integer, + FOREIGN KEY (`created_by`) REFERENCES `mcc-gadgets_user`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +CREATE INDEX `created_by_idx` ON `mcc-gadgets_tempPost` (`created_by`);--> statement-breakpoint +CREATE INDEX `name_idx` ON `mcc-gadgets_tempPost` (`name`); \ No newline at end of file diff --git a/src/server/db/migrations/meta/0001_snapshot.json b/src/server/db/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000..d202223 --- /dev/null +++ b/src/server/db/migrations/meta/0001_snapshot.json @@ -0,0 +1,355 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "ea2b8ee7-e2a7-48ce-96e5-8b7462411ac0", + "prevId": "1682405c-0786-4808-b6b1-d39dfe2f487d", + "tables": { + "mcc-gadgets_account": { + "name": "mcc-gadgets_account", + "columns": { + "user_id": { + "name": "user_id", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_account_id": { + "name": "provider_account_id", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_type": { + "name": "token_type", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session_state": { + "name": "session_state", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "account_user_id_idx": { + "name": "account_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "mcc-gadgets_account_user_id_mcc-gadgets_user_id_fk": { + "name": "mcc-gadgets_account_user_id_mcc-gadgets_user_id_fk", + "tableFrom": "mcc-gadgets_account", + "tableTo": "mcc-gadgets_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "mcc-gadgets_account_provider_provider_account_id_pk": { + "columns": [ + "provider", + "provider_account_id" + ], + "name": "mcc-gadgets_account_provider_provider_account_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcc-gadgets_session": { + "name": "mcc-gadgets_session", + "columns": { + "session_token": { + "name": "session_token", + "type": "text(255)", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + "userId" + ], + "isUnique": false + } + }, + "foreignKeys": { + "mcc-gadgets_session_userId_mcc-gadgets_user_id_fk": { + "name": "mcc-gadgets_session_userId_mcc-gadgets_user_id_fk", + "tableFrom": "mcc-gadgets_session", + "tableTo": "mcc-gadgets_user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcc-gadgets_tempPost": { + "name": "mcc-gadgets_tempPost", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text(256)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "created_by_idx": { + "name": "created_by_idx", + "columns": [ + "created_by" + ], + "isUnique": false + }, + "name_idx": { + "name": "name_idx", + "columns": [ + "name" + ], + "isUnique": false + } + }, + "foreignKeys": { + "mcc-gadgets_tempPost_created_by_mcc-gadgets_user_id_fk": { + "name": "mcc-gadgets_tempPost_created_by_mcc-gadgets_user_id_fk", + "tableFrom": "mcc-gadgets_tempPost", + "tableTo": "mcc-gadgets_user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcc-gadgets_user": { + "name": "mcc-gadgets_user", + "columns": { + "id": { + "name": "id", + "type": "text(255)", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "mcc-gadgets_user_email_unique": { + "name": "mcc-gadgets_user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcc-gadgets_verification_token": { + "name": "mcc-gadgets_verification_token", + "columns": { + "identifier": { + "name": "identifier", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mcc-gadgets_verification_token_identifier_token_pk": { + "columns": [ + "identifier", + "token" + ], + "name": "mcc-gadgets_verification_token_identifier_token_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/src/server/db/migrations/meta/_journal.json b/src/server/db/migrations/meta/_journal.json index 4a76a0a..4da7fbf 100644 --- a/src/server/db/migrations/meta/_journal.json +++ b/src/server/db/migrations/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1745979267601, "tag": "0000_gigantic_carmella_unuscione", "breakpoints": true + }, + { + "idx": 1, + "version": "6", + "when": 1745991519951, + "tag": "0001_needy_butterfly", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index eafc1c3..f1a190c 100644 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -1,4 +1,4 @@ -import { relations } from "drizzle-orm"; +import { relations, sql } from "drizzle-orm"; import { index, int, @@ -16,26 +16,26 @@ import { type AdapterAccount } from "next-auth/adapters"; */ export const createTable = sqliteTableCreator((name) => `mcc-gadgets_${name}`); -// export const posts = createTable( -// "post", -// { -// id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }), -// name: text("name", { length: 256 }), -// createdById: text("created_by", { length: 255 }) -// .notNull() -// .references(() => users.id), -// createdAt: int("created_at", { mode: "timestamp" }) -// .default(sql`(unixepoch())`) -// .notNull(), -// updatedAt: int("updated_at", { mode: "timestamp" }).$onUpdate( -// () => new Date(), -// ), -// }, -// (example) => [ -// index("created_by_idx").on(example.createdById), -// index("name_idx").on(example.name), -// ], -// ); +export const tempPosts = createTable( + "tempPost", + { + id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }), + name: text("name", { length: 256 }), + createdById: text("created_by", { length: 255 }) + .notNull() + .references(() => users.id), + createdAt: int("created_at", { mode: "timestamp" }) + .default(sql`(unixepoch())`) + .notNull(), + updatedAt: int("updated_at", { mode: "timestamp" }).$onUpdate( + () => new Date(), + ), + }, + (example) => [ + index("created_by_idx").on(example.createdById), + index("name_idx").on(example.name), + ], +); export const users = createTable("user", { id: text("id", { length: 255 })