Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Change dev command to generate MySQL DB + auto generate schema

Richie McIlroyf181cfecb94e
diff --git a/.env.example b/.env.example
index 1381da5c6..37fd72736 100644
--- a/.env.example
+++ b/.env.example
@@ -26,7 +26,12 @@ NEXT_PUBLIC_TASKS_URL=http://localhost:3002
NEXT_PUBLIC_LOCAL_MODE=false
# -- database ****************
-DATABASE_URL=mysql://root@localhost:3900/cap
+#
+# This is the URL for the PlanetScale database simulator,
+# which will automatically be created on pnpm dev.
+# It is used for local development only.
+# For production, use the DATABASE_URL from your DB provider. Must include https for production use, mysql:// for local.
+DATABASE_URL=mysql://root:@localhost:3306/planetscale
# Generate a secret with `openssl rand -base64 32`
NEXTAUTH_SECRET=
diff --git a/apps/web/docker-compose.yml b/apps/web/docker-compose.yml
new file mode 100644
index 000000000..b87133ac4
--- /dev/null
+++ b/apps/web/docker-compose.yml
@@ -0,0 +1,36 @@
+# This is meant for local development only. Do not use this in production.
+version: "3.8"
+services:
+ ps-mysql:
+ image: mysql:8.0
+ restart: always
+ environment:
+ MYSQL_DATABASE: planetscale
+ MYSQL_ROOT_HOST: "%"
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
+ command:
+ [
+ "--max_connections=1000",
+ "--default-authentication-plugin=mysql_native_password",
+ ]
+ ports:
+ - 3306:3306
+ volumes:
+ - ps-mysql:/var/lib/mysql
+ planetscale-proxy:
+ image: ghcr.io/mattrobenolt/ps-http-sim:latest
+ command:
+ [
+ "-mysql-no-pass",
+ "-listen-port=3900",
+ "-mysql-dbname=planetscale",
+ "-mysql-addr=ps-mysql",
+ ]
+ depends_on:
+ - ps-mysql
+ ports:
+ - 3900:3900
+ links:
+ - ps-mysql
+volumes:
+ ps-mysql:
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 488d3b215..8543e06ba 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -4,6 +4,12 @@ import million from "million/compiler";
import("dotenv").then(({ config }) => config({ path: "../../.env" }));
+if (process.env.DB_PLANETSCALE_HOST !== undefined) {
+ throw new Error(
+ "DB_PLANETSCALE_HOST no longer supported. Use DATABASE_URL instead. Must start with mysql:// for local dev, and https:// for production."
+ );
+}
+
import fs from "fs";
import path from "path";
diff --git a/package.json b/package.json
index 1253e32c2..04390a48a 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,8 @@
{
"scripts": {
"build": "dotenv -e .env -- turbo run build",
- "dev": "dotenv -e .env -- turbo run dev --no-cache",
+ "dev": "(cd apps/web && docker-compose up -d) && dotenv -e .env -- pnpm --dir packages/database db:generate && dotenv -e .env -- pnpm --dir packages/database db:push && dotenv -e .env -- turbo run dev --no-cache",
+ "dev:manual": "dotenv -e .env -- turbo run dev --no-cache",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"db:push": "dotenv -e .env -- pnpm --dir packages/database db:push",
diff --git a/packages/database/.gitignore b/packages/database/.gitignore
new file mode 100644
index 000000000..7598f9f53
--- /dev/null
+++ b/packages/database/.gitignore
@@ -0,0 +1 @@
+/migrations
\ No newline at end of file
diff --git a/packages/database/drizzle.config.ts b/packages/database/drizzle.config.ts
index 437960ba0..3580cc6e5 100644
--- a/packages/database/drizzle.config.ts
+++ b/packages/database/drizzle.config.ts
@@ -10,5 +10,6 @@ export default {
dbCredentials: {
uri: process.env.DATABASE_URL,
},
+ out: "./migrations",
driver: "mysql2",
} satisfies Config;