Skip to content

Commit

Permalink
Fix fallback createdAt timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
carterworks committed Jan 24, 2025
1 parent 60dc948 commit e7f9b50
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
3 changes: 1 addition & 2 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { defineConfig } from "drizzle-kit";
import schema from "./src/db/schema.ts" with { type: "file" };

export default defineConfig({
out: "./src/db/migrations",
schema,
schema: "./src/db/schema.ts",
dialect: "sqlite",
dbCredentials: {
url: process.env.DB_PATH ?? ":memory:",
Expand Down
19 changes: 19 additions & 0 deletions src/db/migrations/0002_melted_bushwacker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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 (unixepoch() * 1000),
`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;
106 changes: 106 additions & 0 deletions src/db/migrations/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"version": "6",
"dialect": "sqlite",
"id": "804508ad-3e8e-4e5f-a07d-1ab0105b3371",
"prevId": "bd3b440b-12da-4c60-bf23-22d97d060696",
"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": "(unixepoch() * 1000)"
},
"summary": {
"name": "summary",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
7 changes: 7 additions & 0 deletions src/db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1737504467575,
"tag": "0001_awesome_nicolaos",
"breakpoints": true
},
{
"idx": 2,
"version": "6",
"when": 1737747823846,
"tag": "0002_melted_bushwacker",
"breakpoints": true
}
]
}
2 changes: 1 addition & 1 deletion src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const articles = sqliteTable("articles", {
textContent: text(),
htmlContent: text(),
createdAt: integer({ mode: "timestamp_ms" }).default(
sql`(CURRENT_TIMESTAMP)`,
sql`(unixepoch() * 1000)`,
),
summary: text(),
});

0 comments on commit e7f9b50

Please sign in to comment.