From dadeaf484b89c58966ebe5e22ee96c11f719b177 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Mon, 11 Sep 2023 07:07:13 +0800 Subject: [PATCH] Set position in bookmark category to not null and default 0 --- drizzle/0005_medical_pandemic.sql | 2 + drizzle/meta/0005_snapshot.json | 221 ++++++++++++++++++++++++++++++ drizzle/meta/_journal.json | 7 + lib/schema.ts | 2 +- 4 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 drizzle/0005_medical_pandemic.sql create mode 100644 drizzle/meta/0005_snapshot.json diff --git a/drizzle/0005_medical_pandemic.sql b/drizzle/0005_medical_pandemic.sql new file mode 100644 index 0000000..957d694 --- /dev/null +++ b/drizzle/0005_medical_pandemic.sql @@ -0,0 +1,2 @@ +ALTER TABLE "bookmark_categories" ALTER COLUMN "position" SET DEFAULT 0;--> statement-breakpoint +ALTER TABLE "bookmark_categories" ALTER COLUMN "position" SET NOT NULL; \ No newline at end of file diff --git a/drizzle/meta/0005_snapshot.json b/drizzle/meta/0005_snapshot.json new file mode 100644 index 0000000..e1de113 --- /dev/null +++ b/drizzle/meta/0005_snapshot.json @@ -0,0 +1,221 @@ +{ + "version": "5", + "dialect": "pg", + "id": "b205e762-7ad5-4ca6-b5e9-4429fa35d4fe", + "prevId": "b830bd5b-b143-444a-87e6-c36a918276e7", + "tables": { + "bookmarks": { + "name": "bookmarks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "link": { + "name": "link", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "bookmarks_user_id_users_id_fk": { + "name": "bookmarks_user_id_users_id_fk", + "tableFrom": "bookmarks", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "bookmark_categories": { + "name": "bookmark_categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'Other'" + } + }, + "indexes": {}, + "foreignKeys": { + "bookmark_categories_user_id_users_id_fk": { + "name": "bookmark_categories_user_id_users_id_fk", + "tableFrom": "bookmark_categories", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "session": { + "name": "session", + "schema": "", + "columns": { + "sessionToken": { + "name": "sessionToken", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_user_id_users_id_fk": { + "name": "session_user_id_users_id_fk", + "tableFrom": "session", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 10c5c0a..342fd65 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -36,6 +36,13 @@ "when": 1694384709378, "tag": "0004_majestic_vivisector", "breakpoints": true + }, + { + "idx": 5, + "version": "5", + "when": 1694387209769, + "tag": "0005_medical_pandemic", + "breakpoints": true } ] } \ No newline at end of file diff --git a/lib/schema.ts b/lib/schema.ts index 7bc2802..cbc445b 100644 --- a/lib/schema.ts +++ b/lib/schema.ts @@ -38,7 +38,7 @@ export const bookmarkRelations = relations(bookmark, ({ one }) => ({ export const bookmarkCategory = pgTable('bookmark_categories', { id: serial('id').primaryKey(), - position: integer('position'), + position: integer('position').notNull().default(0), userId: integer('user_id') .references(() => user.id) .notNull()