-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add drizzle dependency * Add title to each page * Migrate to drizzle orm * Do not generate css twice in dev mode startup * Update to @types/bun to 1.2 * Update wc-minimap to 0.1.2 * Automatically run schema migrations * Fix drizzle migrations for compiled build
- Loading branch information
1 parent
a990e91
commit 96f9d93
Showing
23 changed files
with
624 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from "drizzle-kit"; | ||
import schema from "./src/db/schema.ts" with { type: "file" }; | ||
|
||
export default defineConfig({ | ||
out: "./src/db/migrations", | ||
schema, | ||
dialect: "sqlite", | ||
dbCredentials: { | ||
url: process.env.DB_PATH ?? ":memory:", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DB_PATH=./articles.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Database } from "bun:sqlite"; | ||
import { sql } from "drizzle-orm"; | ||
import { drizzle } from "drizzle-orm/bun-sqlite"; | ||
import { migrate } from "drizzle-orm/bun-sqlite/migrator"; | ||
import log from "../services/log"; | ||
import * as schema from "./schema"; | ||
|
||
function initalizeDB(location: string = process.env.DB_PATH || ":memory:") { | ||
const client = new Database(location); | ||
const db = drizzle({ client, schema }); | ||
db.run(sql`PRAGMA journal_mode=WAL;`); | ||
runMigrations(db); | ||
return db; | ||
} | ||
|
||
function runMigrations(db: ReturnType<typeof initalizeDB>) { | ||
migrate(db, { migrationsFolder: "./src/db/migrations" }); | ||
log("Migrations complete"); | ||
} | ||
|
||
const db = initalizeDB(); | ||
export default db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- Current sql file was generated after introspecting the database | ||
-- If you want to run this migration please uncomment this code before executing migrations | ||
CREATE TABLE `articles` ( | ||
`url` text PRIMARY KEY, | ||
`title` text, | ||
`author` text, | ||
`published` integer, | ||
`topics` text, | ||
`tags` text, | ||
`markdownContent` text, | ||
`textContent` text, | ||
`htmlContent` text, | ||
`createdAt` integer, | ||
`summary` text | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `schema_version` ( | ||
`version` integer PRIMARY KEY | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
DROP TABLE `schema_version`;--> statement-breakpoint | ||
PRAGMA foreign_keys=OFF;--> statement-breakpoint | ||
CREATE TABLE `__new_articles` ( | ||
`url` text PRIMARY KEY NOT NULL, | ||
`title` text, | ||
`author` text, | ||
`published` integer, | ||
`topics` text, | ||
`tags` text, | ||
`markdownContent` text, | ||
`textContent` text, | ||
`htmlContent` text, | ||
`createdAt` integer DEFAULT (CURRENT_TIMESTAMP), | ||
`summary` text | ||
); | ||
--> statement-breakpoint | ||
INSERT INTO `__new_articles`("url", "title", "author", "published", "topics", "tags", "markdownContent", "textContent", "htmlContent", "createdAt", "summary") SELECT "url", "title", "author", "published", "topics", "tags", "markdownContent", "textContent", "htmlContent", "createdAt", "summary" FROM `articles`;--> statement-breakpoint | ||
DROP TABLE `articles`;--> statement-breakpoint | ||
ALTER TABLE `__new_articles` RENAME TO `articles`;--> statement-breakpoint | ||
PRAGMA foreign_keys=ON; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
{ | ||
"id": "00000000-0000-0000-0000-000000000000", | ||
"prevId": "", | ||
"version": "6", | ||
"dialect": "sqlite", | ||
"tables": { | ||
"articles": { | ||
"name": "articles", | ||
"columns": { | ||
"url": { | ||
"autoincrement": false, | ||
"name": "url", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": false | ||
}, | ||
"title": { | ||
"autoincrement": false, | ||
"name": "title", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"author": { | ||
"autoincrement": false, | ||
"name": "author", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"published": { | ||
"autoincrement": false, | ||
"name": "published", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"topics": { | ||
"autoincrement": false, | ||
"name": "topics", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"tags": { | ||
"autoincrement": false, | ||
"name": "tags", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"markdownContent": { | ||
"autoincrement": false, | ||
"name": "markdownContent", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"textContent": { | ||
"autoincrement": false, | ||
"name": "textContent", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"htmlContent": { | ||
"autoincrement": false, | ||
"name": "htmlContent", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"createdAt": { | ||
"autoincrement": false, | ||
"name": "createdAt", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"summary": { | ||
"autoincrement": false, | ||
"name": "summary", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
}, | ||
"schema_version": { | ||
"name": "schema_version", | ||
"columns": { | ||
"version": { | ||
"autoincrement": false, | ||
"name": "version", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": false | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
} | ||
}, | ||
"views": {}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"version": "6", | ||
"dialect": "sqlite", | ||
"id": "bd3b440b-12da-4c60-bf23-22d97d060696", | ||
"prevId": "00000000-0000-0000-0000-000000000000", | ||
"tables": { | ||
"articles": { | ||
"name": "articles", | ||
"columns": { | ||
"url": { | ||
"name": "url", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"title": { | ||
"name": "title", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"author": { | ||
"name": "author", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"published": { | ||
"name": "published", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"topics": { | ||
"name": "topics", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"tags": { | ||
"name": "tags", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"markdownContent": { | ||
"name": "markdownContent", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"textContent": { | ||
"name": "textContent", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"htmlContent": { | ||
"name": "htmlContent", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"createdAt": { | ||
"name": "createdAt", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false, | ||
"default": "(CURRENT_TIMESTAMP)" | ||
}, | ||
"summary": { | ||
"name": "summary", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
} | ||
}, | ||
"views": {}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
}, | ||
"internal": { | ||
"indexes": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": "7", | ||
"dialect": "sqlite", | ||
"entries": [ | ||
{ | ||
"idx": 0, | ||
"version": "6", | ||
"when": 1737487318393, | ||
"tag": "0000_talented_albert_cleary", | ||
"breakpoints": true | ||
}, | ||
{ | ||
"idx": 1, | ||
"version": "6", | ||
"when": 1737504467575, | ||
"tag": "0001_awesome_nicolaos", | ||
"breakpoints": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// import { relations } from "drizzle-orm/relations"; | ||
// import { } from "./schema"; |
Oops, something went wrong.