Skip to content

Commit

Permalink
chore: remove planetscale
Browse files Browse the repository at this point in the history
  • Loading branch information
warrengalyen committed Jul 31, 2024
1 parent 9930e49 commit 564fdcf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 32 deletions.
6 changes: 2 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# PlanetScale Database Credentials
DATABASE_HOST=
DATABASE_USERNAME=
DATABASE_PASSWORD=
# Database Credentials
DATABASE_URL=

# Clerk Credentials
# These values should be replaced with production keys on the deployed site
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To demo the checkout experience, checkout with a test card number such as `4242

Follow the below steps to run the app locally:

1. Create a database in PlanetScale.
1. Create a MySQL database.
2. Create a local `.env` file with the variables as per the `.env.example` file.
3. Run `npm install`.
4. Generate a migration with `npx drizzle-kit generate:mysql`. This creates a new folder called `migrations-folder` in the root which contains the SQL queries to create the database tables. Migrations are automatically synced with the database through the migration function in `db.ts`. Alternatively, you can run the generated SQL queries from the migration manually through the PlanetScale console and remove the migration function in `db.ts`.
Expand Down
17 changes: 4 additions & 13 deletions db/db.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
// db.ts
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";
import { migrate } from "drizzle-orm/mysql2/migrator";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

// create the connection
const connection = connect({
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
const connection = await mysql.createConnection({
uri: process.env.DATABASE_URL,
});

export const db = drizzle(connection);

// syncs the migrations folder to PlanetScale
process.env.NODE_ENV === "development" &&
migrate(db as any, { migrationsFolder: "./migrations-folder" })
.then((res) => res)
.catch((err) => console.log("Migration error in db.ts:", err));
54 changes: 44 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dependencies": {
"@clerk/nextjs": "^4.17.1",
"@next/mdx": "^13.3.1",
"@planetscale/database": "^1.7.0",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
Expand All @@ -39,11 +38,11 @@
"clsx": "^1.2.1",
"cmdk": "^0.2.0",
"date-fns": "^2.30.0",
"drizzle-orm": "^0.27.2",
"drizzle-orm": "^0.30.10",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"lucide-react": "^0.162.0",
"mysql2": "^3.2.3",
"mysql2": "^3.9.7",
"next": "^13.4.6",
"postcss": "8.4.22",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2015",
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down

0 comments on commit 564fdcf

Please sign in to comment.