Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UN-101: Migrate database to Turso and Libsql #115

Merged
merged 10 commits into from
Aug 30, 2024
21 changes: 12 additions & 9 deletions packages/frontpage/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { defineConfig } from "drizzle-kit";
import { loadEnvConfig } from "@next/env";
import { defineConfig } from "drizzle-kit";

// Load environment variables
loadEnvConfig(process.cwd());

const projectDir = process.cwd();
loadEnvConfig(projectDir);
const URL = process.env.TURSO_CONNECTION_URL!;
const AUTH_TOKEN = process.env.TURSO_AUTH_TOKEN!;

const POSTGRES_URL = process.env.POSTGRES_URL;
if (!POSTGRES_URL) {
throw new Error("POSTGRES_URL is not set");
if (!URL || !AUTH_TOKEN) {
throw new Error("TURSO_CONNECTION_URL and TURSO_AUTH_TOKEN must be set");
}

export default defineConfig({
dialect: "postgresql",
schema: "./lib/schema.ts",
out: "./drizzle",
dialect: "sqlite",
driver: "turso",
strict: true,
verbose: true,
dbCredentials: {
url: POSTGRES_URL,
url: URL,
authToken: AUTH_TOKEN,
},
});
49 changes: 0 additions & 49 deletions packages/frontpage/drizzle/0000_numerous_imperial_guard.sql

This file was deleted.

66 changes: 66 additions & 0 deletions packages/frontpage/drizzle/0000_sturdy_rage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
CREATE TABLE `beta_users` (
`id` integer PRIMARY KEY NOT NULL,
`created_at` text DEFAULT (CURRENT_DATE) NOT NULL,
`did` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `comments` (
`id` integer PRIMARY KEY NOT NULL,
`rkey` text NOT NULL,
`cid` text NOT NULL,
`post_id` integer NOT NULL,
`body` text(10000) NOT NULL,
`created_at` text DEFAULT (CURRENT_DATE) NOT NULL,
`author_did` text NOT NULL,
`status` text DEFAULT 'live',
`parent_comment_id` integer,
FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`parent_comment_id`) REFERENCES `comments`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `comment_votes` (
`id` integer PRIMARY KEY NOT NULL,
`comment_id` integer NOT NULL,
`created_at` text DEFAULT (CURRENT_DATE) NOT NULL,
`author_did` text NOT NULL,
`cid` text NOT NULL,
`rkey` text NOT NULL,
FOREIGN KEY (`comment_id`) REFERENCES `comments`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `consumed_offsets` (
`offset` integer PRIMARY KEY NOT NULL
);
--> statement-breakpoint
CREATE TABLE `posts` (
`id` integer PRIMARY KEY NOT NULL,
`rkey` text NOT NULL,
`cid` text NOT NULL,
`title` text(300) NOT NULL,
`url` text(255) NOT NULL,
`created_at` text DEFAULT (CURRENT_DATE) NOT NULL,
`author_did` text NOT NULL,
`status` text DEFAULT 'live'
);
--> statement-breakpoint
CREATE TABLE `post_votes` (
`id` integer PRIMARY KEY NOT NULL,
`post_id` integer NOT NULL,
`created_at` text DEFAULT (CURRENT_DATE) NOT NULL,
`author_did` text NOT NULL,
`cid` text NOT NULL,
`rkey` text NOT NULL,
FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE UNIQUE INDEX `beta_users_did_unique` ON `beta_users` (`did`);--> statement-breakpoint
CREATE UNIQUE INDEX `comments_cid_unique` ON `comments` (`cid`);--> statement-breakpoint
CREATE UNIQUE INDEX `comments_author_did_rkey_unique` ON `comments` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `comment_votes_cid_unique` ON `comment_votes` (`cid`);--> statement-breakpoint
CREATE UNIQUE INDEX `comment_votes_author_did_rkey_unique` ON `comment_votes` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `comment_votes_author_did_comment_id_unique` ON `comment_votes` (`author_did`,`comment_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `posts_cid_unique` ON `posts` (`cid`);--> statement-breakpoint
CREATE UNIQUE INDEX `posts_author_did_rkey_unique` ON `posts` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `post_votes_cid_unique` ON `post_votes` (`cid`);--> statement-breakpoint
CREATE UNIQUE INDEX `post_votes_author_did_rkey_unique` ON `post_votes` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `post_votes_author_did_post_id_unique` ON `post_votes` (`author_did`,`post_id`);
6 changes: 0 additions & 6 deletions packages/frontpage/drizzle/0001_nice_magma.sql

This file was deleted.

3 changes: 0 additions & 3 deletions packages/frontpage/drizzle/0002_dizzy_juggernaut.sql

This file was deleted.

6 changes: 0 additions & 6 deletions packages/frontpage/drizzle/0003_nervous_violations.sql

This file was deleted.

2 changes: 0 additions & 2 deletions packages/frontpage/drizzle/0004_demonic_the_spike.sql

This file was deleted.

8 changes: 0 additions & 8 deletions packages/frontpage/drizzle/0005_colorful_turbo.sql

This file was deleted.

6 changes: 0 additions & 6 deletions packages/frontpage/drizzle/0006_short_adam_destine.sql

This file was deleted.

20 changes: 0 additions & 20 deletions packages/frontpage/drizzle/0007_smiling_betty_ross.sql

This file was deleted.

6 changes: 0 additions & 6 deletions packages/frontpage/drizzle/0008_oval_master_mold.sql

This file was deleted.

2 changes: 0 additions & 2 deletions packages/frontpage/drizzle/0009_lying_zeigeist.sql

This file was deleted.

5 changes: 0 additions & 5 deletions packages/frontpage/drizzle/0010_regular_roxanne_simpson.sql

This file was deleted.

10 changes: 0 additions & 10 deletions packages/frontpage/drizzle/0011_wooden_mattie_franklin.sql

This file was deleted.

6 changes: 0 additions & 6 deletions packages/frontpage/drizzle/0012_nebulous_vin_gonzales.sql

This file was deleted.

Loading