feat: getting the db ready
This commit is contained in:
1
.env.example
Normal file
1
.env.example
Normal file
@@ -0,0 +1 @@
|
||||
DATABASE_URL=sqlite.db
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,6 +13,9 @@ node_modules
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Database
|
||||
*.db
|
||||
|
||||
# Misc
|
||||
.DS_Store
|
||||
.fleet
|
||||
|
||||
11
drizzle.config.ts
Normal file
11
drizzle.config.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { defineConfig } from 'drizzle-kit'
|
||||
import { env } from './server/env'
|
||||
|
||||
export default defineConfig({
|
||||
schema: './server/db/schema.ts',
|
||||
out: './server/db/migrations',
|
||||
dialect: 'sqlite',
|
||||
dbCredentials: {
|
||||
url: env.DATABASE_URL,
|
||||
},
|
||||
})
|
||||
14
package.json
14
package.json
@@ -8,15 +8,25 @@
|
||||
"preview": "nuxt preview",
|
||||
"postinstall": "nuxt prepare",
|
||||
"lint": "eslint .",
|
||||
"typecheck": "nuxt typecheck"
|
||||
"typecheck": "nuxt typecheck",
|
||||
"db:push": "drizzle-kit push",
|
||||
"db:generate": "drizzle-kit generate",
|
||||
"db:migrate": "drizzle-kit migrate",
|
||||
"db:studio": "drizzle-kit studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxt/ui": "^4.5.1",
|
||||
"better-sqlite3": "^12.8.0",
|
||||
"dotenv": "^17.3.1",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"nuxt": "^4.4.2",
|
||||
"tailwindcss": "^4.2.1"
|
||||
"tailwindcss": "^4.2.1",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nuxt/eslint": "^1.15.2",
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"drizzle-kit": "^0.31.10",
|
||||
"eslint": "^10.0.3",
|
||||
"typescript": "^5.9.3",
|
||||
"vue-tsc": "^3.2.5"
|
||||
|
||||
1056
pnpm-lock.yaml
generated
1056
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -4,3 +4,5 @@ ignoredBuiltDependencies:
|
||||
- esbuild
|
||||
- unrs-resolver
|
||||
- vue-demi
|
||||
onlyBuiltDependencies:
|
||||
- better-sqlite3
|
||||
|
||||
7
server/db/index.ts
Normal file
7
server/db/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import Database from 'better-sqlite3'
|
||||
import { drizzle } from 'drizzle-orm/better-sqlite3'
|
||||
import * as schema from './schema'
|
||||
import { env } from '../env'
|
||||
|
||||
const sqlite = new Database(env.DATABASE_URL)
|
||||
export const db = drizzle(sqlite, { schema })
|
||||
10
server/db/migrations/0000_pretty_mentor.sql
Normal file
10
server/db/migrations/0000_pretty_mentor.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE `links` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`path` text NOT NULL,
|
||||
`url` text NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `links_name_unique` ON `links` (`name`);--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `links_path_unique` ON `links` (`path`);--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `links_url_unique` ON `links` (`url`);
|
||||
78
server/db/migrations/meta/0000_snapshot.json
Normal file
78
server/db/migrations/meta/0000_snapshot.json
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "d03860ad-0d5c-4943-92ba-d704c74e1501",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"links": {
|
||||
"name": "links",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"path": {
|
||||
"name": "path",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"links_name_unique": {
|
||||
"name": "links_name_unique",
|
||||
"columns": [
|
||||
"name"
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"links_path_unique": {
|
||||
"name": "links_path_unique",
|
||||
"columns": [
|
||||
"path"
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"links_url_unique": {
|
||||
"name": "links_url_unique",
|
||||
"columns": [
|
||||
"url"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
13
server/db/migrations/meta/_journal.json
Normal file
13
server/db/migrations/meta/_journal.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1773788954273,
|
||||
"tag": "0000_pretty_mentor",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
8
server/db/schema.ts
Normal file
8
server/db/schema.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const links = sqliteTable("links", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull().unique(),
|
||||
path: text("path").notNull().unique(),
|
||||
url: text("url").notNull().unique(),
|
||||
});
|
||||
8
server/env.ts
Normal file
8
server/env.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'dotenv/config'
|
||||
import { z } from 'zod'
|
||||
|
||||
const schema = z.object({
|
||||
DATABASE_URL: z.string().min(1),
|
||||
})
|
||||
|
||||
export const env = schema.parse(process.env)
|
||||
Reference in New Issue
Block a user