mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 04:04:23 +01:00
Migrate from postgres to sqlite
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
import type { Config } from 'drizzle-kit'
|
||||
import { config } from 'dotenv'
|
||||
|
||||
config()
|
||||
|
||||
export default {
|
||||
dialect: 'postgresql',
|
||||
dialect: 'sqlite',
|
||||
schema: './server/database/schema.ts',
|
||||
out: './server/database/migrations',
|
||||
dbCredentials: {
|
||||
url: process.env.NUXT_POSTGRES_URL,
|
||||
},
|
||||
} satisfies Config
|
||||
|
||||
@@ -38,6 +38,7 @@ export default defineNuxtConfig({
|
||||
analytics: true,
|
||||
blob: true,
|
||||
kv: true,
|
||||
database: true,
|
||||
},
|
||||
|
||||
// Nuxt Icon
|
||||
|
||||
22
package.json
22
package.json
@@ -10,35 +10,31 @@
|
||||
"postinstall": "nuxt prepare && node script.cjs",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"db:generate": "drizzle-kit generate",
|
||||
"db:migrate": "drizzle-kit migrate",
|
||||
"db:push": "drizzle-kit push",
|
||||
"db:pull": "drizzle-kit pull"
|
||||
"db:migrate": "drizzle-kit migrate"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxt/image": "^1.7.1",
|
||||
"@nuxthub/core": "^0.7.7",
|
||||
"@nuxt/image": "^1.8.0",
|
||||
"@nuxthub/core": "^0.7.9",
|
||||
"@nuxtjs/google-fonts": "^3.2.0",
|
||||
"drizzle-orm": "^0.33.0",
|
||||
"h3-zod": "^0.5.3",
|
||||
"nuxt-auth-utils": "^0.3.4",
|
||||
"postgres": "^3.4.4",
|
||||
"vue": "^3.4.38",
|
||||
"nuxt-auth-utils": "^0.3.5",
|
||||
"vue": "^3.5.0",
|
||||
"vue-router": "^4.4.3",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^2.27.3",
|
||||
"@antfu/eslint-config": "^3.0.0",
|
||||
"@nuxt/devtools": "^1.4.1",
|
||||
"@nuxt/ui": "^2.18.4",
|
||||
"@types/node": "^22.5.1",
|
||||
"@types/node": "^22.5.2",
|
||||
"@vueuse/core": "^11.0.3",
|
||||
"@vueuse/nuxt": "^11.0.3",
|
||||
"dotenv": "^16.4.5",
|
||||
"drizzle-kit": "^0.24.2",
|
||||
"eslint": "^9.9.1",
|
||||
"nuxt": "^3.13.0",
|
||||
"typescript": "^5.5.4",
|
||||
"vue-tsc": "^2.0.29",
|
||||
"wrangler": "^3.72.3"
|
||||
"vue-tsc": "^2.1.4",
|
||||
"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 filesToModify = [
|
||||
'node_modules/drizzle-orm/pg-core/columns/timestamp.js',
|
||||
'node_modules/drizzle-orm/pg-core/columns/timestamp.cjs',
|
||||
'node_modules/drizzle-orm/sqlite-core/columns/integer.js',
|
||||
'node_modules/drizzle-orm/sqlite-core/columns/integer.cjs',
|
||||
]
|
||||
|
||||
filesToModify.forEach((file) => {
|
||||
@@ -13,8 +13,8 @@ filesToModify.forEach((file) => {
|
||||
if (fs.existsSync(filePath)) {
|
||||
let fileContent = fs.readFileSync(filePath, 'utf8')
|
||||
fileContent = fileContent.replace(
|
||||
'return value.toISOString()',
|
||||
'return value',
|
||||
'value.getTime()',
|
||||
'value',
|
||||
)
|
||||
fs.writeFileSync(filePath, fileContent, 'utf8')
|
||||
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",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"tables": {
|
||||
"public.categories": {
|
||||
"categories": {
|
||||
"name": "categories",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"name_visible": {
|
||||
"name": "name_visible",
|
||||
"type": "boolean",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"icon": {
|
||||
@@ -33,6 +35,7 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'i-ph:circle-wavy-question-duotone'"
|
||||
},
|
||||
"color": {
|
||||
@@ -40,27 +43,29 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'gray'"
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp(0) with time zone",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp(0) with time zone",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
@@ -82,28 +87,30 @@
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"public.tabs": {
|
||||
"tabs": {
|
||||
"name": "tabs",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"primary": {
|
||||
"name": "primary",
|
||||
"type": "boolean",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"icon": {
|
||||
@@ -111,6 +118,7 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'i-ph:circle-wavy-question-duotone'"
|
||||
},
|
||||
"color": {
|
||||
@@ -118,6 +126,7 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'gray'"
|
||||
},
|
||||
"link": {
|
||||
@@ -125,27 +134,29 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"category_id": {
|
||||
"name": "category_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp(0) with time zone",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp(0) with time zone",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
@@ -167,63 +178,71 @@
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"public.users": {
|
||||
"users": {
|
||||
"name": "users",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"github_id": {
|
||||
"name": "github_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"github_token": {
|
||||
"name": "github_token",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"google_id": {
|
||||
"name": "google_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"google_token": {
|
||||
"name": "google_token",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"avatar": {
|
||||
@@ -231,13 +250,15 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"private": {
|
||||
"name": "private",
|
||||
"type": "boolean",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"language": {
|
||||
@@ -245,6 +266,7 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'en-EN'"
|
||||
},
|
||||
"location": {
|
||||
@@ -252,81 +274,74 @@
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'unknown'"
|
||||
},
|
||||
"subscription": {
|
||||
"name": "subscription",
|
||||
"type": "subscription",
|
||||
"typeSchema": "public",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'free'"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp(0) with time zone",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp(0) with time zone",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"indexes": {
|
||||
"users_username_unique": {
|
||||
"name": "users_username_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"username"
|
||||
]
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"users_email_unique": {
|
||||
"name": "users_email_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"email"
|
||||
]
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"users_github_id_unique": {
|
||||
"name": "users_github_id_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"github_id"
|
||||
]
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"users_google_id_unique": {
|
||||
"name": "users_google_id_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"google_id"
|
||||
]
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
}
|
||||
},
|
||||
"enums": {
|
||||
"public.subscription": {
|
||||
"name": "subscription",
|
||||
"schema": "public",
|
||||
"values": [
|
||||
"free",
|
||||
"paid"
|
||||
]
|
||||
}
|
||||
},
|
||||
"schemas": {},
|
||||
"sequences": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1725302227098,
|
||||
"tag": "0000_noisy_randall_flagg",
|
||||
"version": "6",
|
||||
"when": 1725385265625,
|
||||
"tag": "0000_grey_marvel_zombies",
|
||||
"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 { id, timestamps } from '../utils/dbFields'
|
||||
import { Subscription } from '../../types/types'
|
||||
|
||||
export const subscriptionEnum = pgEnum('subscription', Subscription)
|
||||
|
||||
export const users = pgTable('users', {
|
||||
export const users = sqliteTable('users', {
|
||||
id,
|
||||
username: text('username').notNull().unique(),
|
||||
name: text('name').notNull(),
|
||||
@@ -16,17 +14,17 @@ export const users = pgTable('users', {
|
||||
googleToken: text('google_token'),
|
||||
description: text('description').default(''),
|
||||
avatar: text('avatar').default(''),
|
||||
private: boolean('private').default(false),
|
||||
private: integer('private', { mode: 'boolean' }).default(false),
|
||||
language: text('language').default('en-EN'),
|
||||
location: text('location').default('unknown'),
|
||||
subscription: subscriptionEnum('subscription').default('free'),
|
||||
subscription: text('subscription', { enum: Subscription }).default('free'),
|
||||
...timestamps,
|
||||
})
|
||||
|
||||
export const categories = pgTable('categories', {
|
||||
export const categories = sqliteTable('categories', {
|
||||
id,
|
||||
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'),
|
||||
color: text('color').default('gray'),
|
||||
userId: integer('user_id')
|
||||
@@ -35,10 +33,10 @@ export const categories = pgTable('categories', {
|
||||
...timestamps,
|
||||
})
|
||||
|
||||
export const tabs = pgTable('tabs', {
|
||||
export const tabs = sqliteTable('tabs', {
|
||||
id,
|
||||
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'),
|
||||
color: text('color').default('gray'),
|
||||
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/postgres-js'
|
||||
import { drizzle } from 'drizzle-orm/d1'
|
||||
import * as schema from '../database/schema'
|
||||
|
||||
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 function useDrizzle() {
|
||||
const config = useRuntimeConfig()
|
||||
return drizzle(postgres(config.postgres.url, { prepare: false, max: 50 }), { schema })
|
||||
return drizzle(hubDatabase(), { schema })
|
||||
}
|
||||
|
||||
export type UserInsert = typeof schema.users.$inferInsert
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { serial, timestamp } from 'drizzle-orm/pg-core'
|
||||
/**
|
||||
* A centralized list of standardized Drizzle ORM schema field definitions to prevent duplication errors
|
||||
*/
|
||||
import { integer } from 'drizzle-orm/sqlite-core'
|
||||
|
||||
export const createdAt = timestamp('created_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow()
|
||||
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 id = integer('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 = {
|
||||
createdAt,
|
||||
|
||||
Reference in New Issue
Block a user