mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 12:14:33 +01:00
Migrate from postgres to sqlite
This commit is contained in:
@@ -1,13 +1,7 @@
|
|||||||
import type { Config } from 'drizzle-kit'
|
import type { Config } from 'drizzle-kit'
|
||||||
import { config } from 'dotenv'
|
|
||||||
|
|
||||||
config()
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
dialect: 'postgresql',
|
dialect: 'sqlite',
|
||||||
schema: './server/database/schema.ts',
|
schema: './server/database/schema.ts',
|
||||||
out: './server/database/migrations',
|
out: './server/database/migrations',
|
||||||
dbCredentials: {
|
|
||||||
url: process.env.NUXT_POSTGRES_URL,
|
|
||||||
},
|
|
||||||
} satisfies Config
|
} satisfies Config
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export default defineNuxtConfig({
|
|||||||
analytics: true,
|
analytics: true,
|
||||||
blob: true,
|
blob: true,
|
||||||
kv: true,
|
kv: true,
|
||||||
|
database: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Nuxt Icon
|
// Nuxt Icon
|
||||||
|
|||||||
22
package.json
22
package.json
@@ -10,35 +10,31 @@
|
|||||||
"postinstall": "nuxt prepare && node script.cjs",
|
"postinstall": "nuxt prepare && node script.cjs",
|
||||||
"lint:fix": "eslint . --fix",
|
"lint:fix": "eslint . --fix",
|
||||||
"db:generate": "drizzle-kit generate",
|
"db:generate": "drizzle-kit generate",
|
||||||
"db:migrate": "drizzle-kit migrate",
|
"db:migrate": "drizzle-kit migrate"
|
||||||
"db:push": "drizzle-kit push",
|
|
||||||
"db:pull": "drizzle-kit pull"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/image": "^1.7.1",
|
"@nuxt/image": "^1.8.0",
|
||||||
"@nuxthub/core": "^0.7.7",
|
"@nuxthub/core": "^0.7.9",
|
||||||
"@nuxtjs/google-fonts": "^3.2.0",
|
"@nuxtjs/google-fonts": "^3.2.0",
|
||||||
"drizzle-orm": "^0.33.0",
|
"drizzle-orm": "^0.33.0",
|
||||||
"h3-zod": "^0.5.3",
|
"h3-zod": "^0.5.3",
|
||||||
"nuxt-auth-utils": "^0.3.4",
|
"nuxt-auth-utils": "^0.3.5",
|
||||||
"postgres": "^3.4.4",
|
"vue": "^3.5.0",
|
||||||
"vue": "^3.4.38",
|
|
||||||
"vue-router": "^4.4.3",
|
"vue-router": "^4.4.3",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^2.27.3",
|
"@antfu/eslint-config": "^3.0.0",
|
||||||
"@nuxt/devtools": "^1.4.1",
|
"@nuxt/devtools": "^1.4.1",
|
||||||
"@nuxt/ui": "^2.18.4",
|
"@nuxt/ui": "^2.18.4",
|
||||||
"@types/node": "^22.5.1",
|
"@types/node": "^22.5.2",
|
||||||
"@vueuse/core": "^11.0.3",
|
"@vueuse/core": "^11.0.3",
|
||||||
"@vueuse/nuxt": "^11.0.3",
|
"@vueuse/nuxt": "^11.0.3",
|
||||||
"dotenv": "^16.4.5",
|
|
||||||
"drizzle-kit": "^0.24.2",
|
"drizzle-kit": "^0.24.2",
|
||||||
"eslint": "^9.9.1",
|
"eslint": "^9.9.1",
|
||||||
"nuxt": "^3.13.0",
|
"nuxt": "^3.13.0",
|
||||||
"typescript": "^5.5.4",
|
"typescript": "^5.5.4",
|
||||||
"vue-tsc": "^2.0.29",
|
"vue-tsc": "^2.1.4",
|
||||||
"wrangler": "^3.72.3"
|
"wrangler": "^3.74.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
567
pnpm-lock.yaml
generated
567
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,8 @@ const fs = require('node:fs')
|
|||||||
const path = require('node:path')
|
const path = require('node:path')
|
||||||
|
|
||||||
const filesToModify = [
|
const filesToModify = [
|
||||||
'node_modules/drizzle-orm/pg-core/columns/timestamp.js',
|
'node_modules/drizzle-orm/sqlite-core/columns/integer.js',
|
||||||
'node_modules/drizzle-orm/pg-core/columns/timestamp.cjs',
|
'node_modules/drizzle-orm/sqlite-core/columns/integer.cjs',
|
||||||
]
|
]
|
||||||
|
|
||||||
filesToModify.forEach((file) => {
|
filesToModify.forEach((file) => {
|
||||||
@@ -13,8 +13,8 @@ filesToModify.forEach((file) => {
|
|||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
let fileContent = fs.readFileSync(filePath, 'utf8')
|
let fileContent = fs.readFileSync(filePath, 'utf8')
|
||||||
fileContent = fileContent.replace(
|
fileContent = fileContent.replace(
|
||||||
'return value.toISOString()',
|
'value.getTime()',
|
||||||
'return value',
|
'value',
|
||||||
)
|
)
|
||||||
fs.writeFileSync(filePath, fileContent, 'utf8')
|
fs.writeFileSync(filePath, fileContent, 'utf8')
|
||||||
console.log(`Modified: ${file}`)
|
console.log(`Modified: ${file}`)
|
||||||
|
|||||||
48
server/database/migrations/0000_grey_marvel_zombies.sql
Normal file
48
server/database/migrations/0000_grey_marvel_zombies.sql
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
CREATE TABLE `categories` (
|
||||||
|
`id` integer PRIMARY KEY NOT NULL,
|
||||||
|
`name` text DEFAULT '',
|
||||||
|
`name_visible` integer DEFAULT true,
|
||||||
|
`icon` text DEFAULT 'i-ph:circle-wavy-question-duotone',
|
||||||
|
`color` text DEFAULT 'gray',
|
||||||
|
`user_id` integer NOT NULL,
|
||||||
|
`created_at` integer,
|
||||||
|
`updated_at` integer,
|
||||||
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `tabs` (
|
||||||
|
`id` integer PRIMARY KEY NOT NULL,
|
||||||
|
`name` text DEFAULT '',
|
||||||
|
`primary` integer DEFAULT false,
|
||||||
|
`icon` text DEFAULT 'i-ph:circle-wavy-question-duotone',
|
||||||
|
`color` text DEFAULT 'gray',
|
||||||
|
`link` text DEFAULT '',
|
||||||
|
`category_id` integer NOT NULL,
|
||||||
|
`created_at` integer,
|
||||||
|
`updated_at` integer,
|
||||||
|
FOREIGN KEY (`category_id`) REFERENCES `categories`(`id`) ON UPDATE no action ON DELETE cascade
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `users` (
|
||||||
|
`id` integer PRIMARY KEY NOT NULL,
|
||||||
|
`username` text NOT NULL,
|
||||||
|
`name` text NOT NULL,
|
||||||
|
`email` text NOT NULL,
|
||||||
|
`github_id` text,
|
||||||
|
`github_token` text,
|
||||||
|
`google_id` text,
|
||||||
|
`google_token` text,
|
||||||
|
`description` text DEFAULT '',
|
||||||
|
`avatar` text DEFAULT '',
|
||||||
|
`private` integer DEFAULT false,
|
||||||
|
`language` text DEFAULT 'en-EN',
|
||||||
|
`location` text DEFAULT 'unknown',
|
||||||
|
`subscription` text DEFAULT 'free',
|
||||||
|
`created_at` integer,
|
||||||
|
`updated_at` integer
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX `users_username_unique` ON `users` (`username`);--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX `users_github_id_unique` ON `users` (`github_id`);--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX `users_google_id_unique` ON `users` (`google_id`);
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
DO $$ BEGIN
|
|
||||||
CREATE TYPE "public"."subscription" AS ENUM('free', 'paid');
|
|
||||||
EXCEPTION
|
|
||||||
WHEN duplicate_object THEN null;
|
|
||||||
END $$;
|
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE TABLE IF NOT EXISTS "categories" (
|
|
||||||
"id" serial PRIMARY KEY NOT NULL,
|
|
||||||
"name" text DEFAULT '',
|
|
||||||
"name_visible" boolean DEFAULT true,
|
|
||||||
"icon" text DEFAULT 'i-ph:circle-wavy-question-duotone',
|
|
||||||
"color" text DEFAULT 'gray',
|
|
||||||
"user_id" integer NOT NULL,
|
|
||||||
"created_at" timestamp(0) with time zone DEFAULT now(),
|
|
||||||
"updated_at" timestamp(0) with time zone DEFAULT now()
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE TABLE IF NOT EXISTS "tabs" (
|
|
||||||
"id" serial PRIMARY KEY NOT NULL,
|
|
||||||
"name" text DEFAULT '',
|
|
||||||
"primary" boolean DEFAULT false,
|
|
||||||
"icon" text DEFAULT 'i-ph:circle-wavy-question-duotone',
|
|
||||||
"color" text DEFAULT 'gray',
|
|
||||||
"link" text DEFAULT '',
|
|
||||||
"category_id" integer NOT NULL,
|
|
||||||
"created_at" timestamp(0) with time zone DEFAULT now(),
|
|
||||||
"updated_at" timestamp(0) with time zone DEFAULT now()
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE TABLE IF NOT EXISTS "users" (
|
|
||||||
"id" serial PRIMARY KEY NOT NULL,
|
|
||||||
"username" text NOT NULL,
|
|
||||||
"name" text NOT NULL,
|
|
||||||
"email" text NOT NULL,
|
|
||||||
"github_id" text,
|
|
||||||
"github_token" text,
|
|
||||||
"google_id" text,
|
|
||||||
"google_token" text,
|
|
||||||
"description" text DEFAULT '',
|
|
||||||
"avatar" text DEFAULT '',
|
|
||||||
"private" boolean DEFAULT false,
|
|
||||||
"language" text DEFAULT 'en-EN',
|
|
||||||
"location" text DEFAULT 'unknown',
|
|
||||||
"subscription" "subscription" DEFAULT 'free',
|
|
||||||
"created_at" timestamp(0) with time zone DEFAULT now(),
|
|
||||||
"updated_at" timestamp(0) with time zone DEFAULT now(),
|
|
||||||
CONSTRAINT "users_username_unique" UNIQUE("username"),
|
|
||||||
CONSTRAINT "users_email_unique" UNIQUE("email"),
|
|
||||||
CONSTRAINT "users_github_id_unique" UNIQUE("github_id"),
|
|
||||||
CONSTRAINT "users_google_id_unique" UNIQUE("google_id")
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
DO $$ BEGIN
|
|
||||||
ALTER TABLE "categories" ADD CONSTRAINT "categories_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
|
||||||
EXCEPTION
|
|
||||||
WHEN duplicate_object THEN null;
|
|
||||||
END $$;
|
|
||||||
--> statement-breakpoint
|
|
||||||
DO $$ BEGIN
|
|
||||||
ALTER TABLE "tabs" ADD CONSTRAINT "tabs_category_id_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."categories"("id") ON DELETE cascade ON UPDATE no action;
|
|
||||||
EXCEPTION
|
|
||||||
WHEN duplicate_object THEN null;
|
|
||||||
END $$;
|
|
||||||
@@ -1,31 +1,33 @@
|
|||||||
{
|
{
|
||||||
"id": "21470761-4c33-4588-be9b-4927bbcbfe2c",
|
"version": "6",
|
||||||
|
"dialect": "sqlite",
|
||||||
|
"id": "2764f724-b59e-4de8-b7e7-691122ed7e73",
|
||||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||||
"version": "7",
|
|
||||||
"dialect": "postgresql",
|
|
||||||
"tables": {
|
"tables": {
|
||||||
"public.categories": {
|
"categories": {
|
||||||
"name": "categories",
|
"name": "categories",
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
"columns": {
|
||||||
"id": {
|
"id": {
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"type": "serial",
|
"type": "integer",
|
||||||
"primaryKey": true,
|
"primaryKey": true,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "''"
|
"default": "''"
|
||||||
},
|
},
|
||||||
"name_visible": {
|
"name_visible": {
|
||||||
"name": "name_visible",
|
"name": "name_visible",
|
||||||
"type": "boolean",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"icon": {
|
"icon": {
|
||||||
@@ -33,6 +35,7 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'i-ph:circle-wavy-question-duotone'"
|
"default": "'i-ph:circle-wavy-question-duotone'"
|
||||||
},
|
},
|
||||||
"color": {
|
"color": {
|
||||||
@@ -40,27 +43,29 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'gray'"
|
"default": "'gray'"
|
||||||
},
|
},
|
||||||
"user_id": {
|
"user_id": {
|
||||||
"name": "user_id",
|
"name": "user_id",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type": "timestamp(0) with time zone",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": "now()"
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"updated_at": {
|
"updated_at": {
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type": "timestamp(0) with time zone",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": "now()"
|
"autoincrement": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexes": {},
|
"indexes": {},
|
||||||
@@ -82,28 +87,30 @@
|
|||||||
"compositePrimaryKeys": {},
|
"compositePrimaryKeys": {},
|
||||||
"uniqueConstraints": {}
|
"uniqueConstraints": {}
|
||||||
},
|
},
|
||||||
"public.tabs": {
|
"tabs": {
|
||||||
"name": "tabs",
|
"name": "tabs",
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
"columns": {
|
||||||
"id": {
|
"id": {
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"type": "serial",
|
"type": "integer",
|
||||||
"primaryKey": true,
|
"primaryKey": true,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "''"
|
"default": "''"
|
||||||
},
|
},
|
||||||
"primary": {
|
"primary": {
|
||||||
"name": "primary",
|
"name": "primary",
|
||||||
"type": "boolean",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"icon": {
|
"icon": {
|
||||||
@@ -111,6 +118,7 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'i-ph:circle-wavy-question-duotone'"
|
"default": "'i-ph:circle-wavy-question-duotone'"
|
||||||
},
|
},
|
||||||
"color": {
|
"color": {
|
||||||
@@ -118,6 +126,7 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'gray'"
|
"default": "'gray'"
|
||||||
},
|
},
|
||||||
"link": {
|
"link": {
|
||||||
@@ -125,27 +134,29 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "''"
|
"default": "''"
|
||||||
},
|
},
|
||||||
"category_id": {
|
"category_id": {
|
||||||
"name": "category_id",
|
"name": "category_id",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type": "timestamp(0) with time zone",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": "now()"
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"updated_at": {
|
"updated_at": {
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type": "timestamp(0) with time zone",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": "now()"
|
"autoincrement": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexes": {},
|
"indexes": {},
|
||||||
@@ -167,63 +178,71 @@
|
|||||||
"compositePrimaryKeys": {},
|
"compositePrimaryKeys": {},
|
||||||
"uniqueConstraints": {}
|
"uniqueConstraints": {}
|
||||||
},
|
},
|
||||||
"public.users": {
|
"users": {
|
||||||
"name": "users",
|
"name": "users",
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
"columns": {
|
||||||
"id": {
|
"id": {
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"type": "serial",
|
"type": "integer",
|
||||||
"primaryKey": true,
|
"primaryKey": true,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"username": {
|
"username": {
|
||||||
"name": "username",
|
"name": "username",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"email": {
|
"email": {
|
||||||
"name": "email",
|
"name": "email",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"github_id": {
|
"github_id": {
|
||||||
"name": "github_id",
|
"name": "github_id",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"github_token": {
|
"github_token": {
|
||||||
"name": "github_token",
|
"name": "github_token",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"google_id": {
|
"google_id": {
|
||||||
"name": "google_id",
|
"name": "google_id",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"google_token": {
|
"google_token": {
|
||||||
"name": "google_token",
|
"name": "google_token",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"name": "description",
|
"name": "description",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "''"
|
"default": "''"
|
||||||
},
|
},
|
||||||
"avatar": {
|
"avatar": {
|
||||||
@@ -231,13 +250,15 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "''"
|
"default": "''"
|
||||||
},
|
},
|
||||||
"private": {
|
"private": {
|
||||||
"name": "private",
|
"name": "private",
|
||||||
"type": "boolean",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
@@ -245,6 +266,7 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'en-EN'"
|
"default": "'en-EN'"
|
||||||
},
|
},
|
||||||
"location": {
|
"location": {
|
||||||
@@ -252,81 +274,74 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'unknown'"
|
"default": "'unknown'"
|
||||||
},
|
},
|
||||||
"subscription": {
|
"subscription": {
|
||||||
"name": "subscription",
|
"name": "subscription",
|
||||||
"type": "subscription",
|
"type": "text",
|
||||||
"typeSchema": "public",
|
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
"default": "'free'"
|
"default": "'free'"
|
||||||
},
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type": "timestamp(0) with time zone",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": "now()"
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
"updated_at": {
|
"updated_at": {
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type": "timestamp(0) with time zone",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": "now()"
|
"autoincrement": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexes": {},
|
"indexes": {
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {
|
|
||||||
"users_username_unique": {
|
"users_username_unique": {
|
||||||
"name": "users_username_unique",
|
"name": "users_username_unique",
|
||||||
"nullsNotDistinct": false,
|
|
||||||
"columns": [
|
"columns": [
|
||||||
"username"
|
"username"
|
||||||
]
|
],
|
||||||
|
"isUnique": true
|
||||||
},
|
},
|
||||||
"users_email_unique": {
|
"users_email_unique": {
|
||||||
"name": "users_email_unique",
|
"name": "users_email_unique",
|
||||||
"nullsNotDistinct": false,
|
|
||||||
"columns": [
|
"columns": [
|
||||||
"email"
|
"email"
|
||||||
]
|
],
|
||||||
|
"isUnique": true
|
||||||
},
|
},
|
||||||
"users_github_id_unique": {
|
"users_github_id_unique": {
|
||||||
"name": "users_github_id_unique",
|
"name": "users_github_id_unique",
|
||||||
"nullsNotDistinct": false,
|
|
||||||
"columns": [
|
"columns": [
|
||||||
"github_id"
|
"github_id"
|
||||||
]
|
],
|
||||||
|
"isUnique": true
|
||||||
},
|
},
|
||||||
"users_google_id_unique": {
|
"users_google_id_unique": {
|
||||||
"name": "users_google_id_unique",
|
"name": "users_google_id_unique",
|
||||||
"nullsNotDistinct": false,
|
|
||||||
"columns": [
|
"columns": [
|
||||||
"google_id"
|
"google_id"
|
||||||
]
|
],
|
||||||
|
"isUnique": true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"enums": {
|
"enums": {},
|
||||||
"public.subscription": {
|
|
||||||
"name": "subscription",
|
|
||||||
"schema": "public",
|
|
||||||
"values": [
|
|
||||||
"free",
|
|
||||||
"paid"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"schemas": {},
|
|
||||||
"sequences": {},
|
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"columns": {},
|
|
||||||
"schemas": {},
|
"schemas": {},
|
||||||
"tables": {}
|
"tables": {},
|
||||||
|
"columns": {}
|
||||||
|
},
|
||||||
|
"internal": {
|
||||||
|
"indexes": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"version": "7",
|
"version": "7",
|
||||||
"dialect": "postgresql",
|
"dialect": "sqlite",
|
||||||
"entries": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"version": "7",
|
"version": "6",
|
||||||
"when": 1725302227098,
|
"when": 1725385265625,
|
||||||
"tag": "0000_noisy_randall_flagg",
|
"tag": "0000_grey_marvel_zombies",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { boolean, integer, pgEnum, pgTable, text } from 'drizzle-orm/pg-core'
|
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
||||||
import { relations } from 'drizzle-orm'
|
import { relations } from 'drizzle-orm'
|
||||||
import { id, timestamps } from '../utils/dbFields'
|
import { id, timestamps } from '../utils/dbFields'
|
||||||
import { Subscription } from '../../types/types'
|
import { Subscription } from '../../types/types'
|
||||||
|
|
||||||
export const subscriptionEnum = pgEnum('subscription', Subscription)
|
export const users = sqliteTable('users', {
|
||||||
|
|
||||||
export const users = pgTable('users', {
|
|
||||||
id,
|
id,
|
||||||
username: text('username').notNull().unique(),
|
username: text('username').notNull().unique(),
|
||||||
name: text('name').notNull(),
|
name: text('name').notNull(),
|
||||||
@@ -16,17 +14,17 @@ export const users = pgTable('users', {
|
|||||||
googleToken: text('google_token'),
|
googleToken: text('google_token'),
|
||||||
description: text('description').default(''),
|
description: text('description').default(''),
|
||||||
avatar: text('avatar').default(''),
|
avatar: text('avatar').default(''),
|
||||||
private: boolean('private').default(false),
|
private: integer('private', { mode: 'boolean' }).default(false),
|
||||||
language: text('language').default('en-EN'),
|
language: text('language').default('en-EN'),
|
||||||
location: text('location').default('unknown'),
|
location: text('location').default('unknown'),
|
||||||
subscription: subscriptionEnum('subscription').default('free'),
|
subscription: text('subscription', { enum: Subscription }).default('free'),
|
||||||
...timestamps,
|
...timestamps,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const categories = pgTable('categories', {
|
export const categories = sqliteTable('categories', {
|
||||||
id,
|
id,
|
||||||
name: text('name').default(''),
|
name: text('name').default(''),
|
||||||
nameVisible: boolean('name_visible').default(true),
|
nameVisible: integer('name_visible', { mode: 'boolean' }).default(true),
|
||||||
icon: text('icon').default('i-ph:circle-wavy-question-duotone'),
|
icon: text('icon').default('i-ph:circle-wavy-question-duotone'),
|
||||||
color: text('color').default('gray'),
|
color: text('color').default('gray'),
|
||||||
userId: integer('user_id')
|
userId: integer('user_id')
|
||||||
@@ -35,10 +33,10 @@ export const categories = pgTable('categories', {
|
|||||||
...timestamps,
|
...timestamps,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const tabs = pgTable('tabs', {
|
export const tabs = sqliteTable('tabs', {
|
||||||
id,
|
id,
|
||||||
name: text('name').default(''),
|
name: text('name').default(''),
|
||||||
primary: boolean('primary').default(false),
|
primary: integer('primary', { mode: 'boolean' }).default(false),
|
||||||
icon: text('icon').default('i-ph:circle-wavy-question-duotone'),
|
icon: text('icon').default('i-ph:circle-wavy-question-duotone'),
|
||||||
color: text('color').default('gray'),
|
color: text('color').default('gray'),
|
||||||
link: text('link').default(''),
|
link: text('link').default(''),
|
||||||
|
|||||||
17
server/plugins/migrations.ts
Normal file
17
server/plugins/migrations.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { consola } from 'consola'
|
||||||
|
import { migrate } from 'drizzle-orm/d1/migrator'
|
||||||
|
|
||||||
|
export default defineNitroPlugin(async () => {
|
||||||
|
if (!import.meta.dev)
|
||||||
|
return
|
||||||
|
|
||||||
|
onHubReady(async () => {
|
||||||
|
await migrate(useDrizzle(), { migrationsFolder: 'server/database/migrations' })
|
||||||
|
.then(() => {
|
||||||
|
consola.success('Database migrations done')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
consola.error('Database migrations failed', err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import postgres from 'postgres'
|
import { drizzle } from 'drizzle-orm/d1'
|
||||||
import { drizzle } from 'drizzle-orm/postgres-js'
|
|
||||||
import * as schema from '../database/schema'
|
import * as schema from '../database/schema'
|
||||||
|
|
||||||
export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
|
export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
|
||||||
@@ -7,8 +6,7 @@ export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
|
|||||||
export const tables = schema
|
export const tables = schema
|
||||||
|
|
||||||
export function useDrizzle() {
|
export function useDrizzle() {
|
||||||
const config = useRuntimeConfig()
|
return drizzle(hubDatabase(), { schema })
|
||||||
return drizzle(postgres(config.postgres.url, { prepare: false, max: 50 }), { schema })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserInsert = typeof schema.users.$inferInsert
|
export type UserInsert = typeof schema.users.$inferInsert
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { serial, timestamp } from 'drizzle-orm/pg-core'
|
import { integer } from 'drizzle-orm/sqlite-core'
|
||||||
/**
|
|
||||||
* A centralized list of standardized Drizzle ORM schema field definitions to prevent duplication errors
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const createdAt = timestamp('created_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow()
|
export const id = integer('id').primaryKey()
|
||||||
export const updatedAt = timestamp('updated_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow().$onUpdateFn(() => sql`(current_timestamp)`)
|
|
||||||
export const id = serial('id').primaryKey()
|
export const createdAt
|
||||||
|
= integer('created_at', { mode: 'timestamp' })
|
||||||
|
.$defaultFn(() => new Date())
|
||||||
|
|
||||||
|
export const updatedAt
|
||||||
|
= integer('updated_at', { mode: 'timestamp' })
|
||||||
|
.$onUpdateFn(() => new Date())
|
||||||
|
.$defaultFn(() => new Date())
|
||||||
|
|
||||||
export const timestamps = {
|
export const timestamps = {
|
||||||
createdAt,
|
createdAt,
|
||||||
|
|||||||
Reference in New Issue
Block a user