update to env and gitignore

This commit is contained in:
ImAlpha 2023-11-30 02:25:32 -08:00
parent 1c5b853205
commit f9ceebcd36
13 changed files with 2640 additions and 60 deletions

View File

@ -5,5 +5,9 @@
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
# DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
DATABASE_URL="mysql://root:%21Plop2099341723@192.168.50.190:3306/db"
MAPS_API_KEY="https://www.google.com/maps/embed/v1/place?q=place_id:ChIJQ-7Uc0BitocRQZASTWUyN04&key=AIzaSyBS4qOnpT4llaFa_UKMpeWike3lzDvFZ1U"
# DATABASE_URL="mysql://root:%21Plop2099341723@192.168.50.190:3306/db"
MAPS_API_KEY="https://www.google.com/maps/embed/v1/place?q=place_id:ChIJQ-7Uc0BitocRQZASTWUyN04&key=AIzaSyBS4qOnpT4llaFa_UKMpeWike3lzDvFZ1U"
DATABASE_HOST="aws.connect.psdb.cloud"
DATABASE_USERNAME="11lq0wcjbxyku4zmubji"
DATABASE_PASSWORD="pscale_pw_AyxGMWCMpaZOsaeeXXem8mrxXPRNJEG0uPUrW2zo1f8"

View File

@ -19,6 +19,7 @@
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
@ -26,6 +27,7 @@ yarn-error.log*
# local env files
.env*.local
.env
# vercel
.vercel

View File

@ -0,0 +1,13 @@
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
import * as schema from './schema';
export const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
multipleStatements: true,
});
export const db = drizzle(connection, { schema });

View File

@ -0,0 +1,12 @@
// db/index.ts
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";
// create the connection
const connection = connect({
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
});
const db = drizzle(connection);

View File

@ -0,0 +1,9 @@
import "dotenv/config";
import { migrate } from "drizzle-orm/mysql2/migrator";
import { db, connection } from "./db";
// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: "./drizzle" });
// Don't forget to close the connection, otherwise the script will hang
await connection.end();

View File

@ -0,0 +1,26 @@
// db/schema.ts
import {
index,
int,
mysqlTable,
bigint,
varchar,
} from "drizzle-orm/mysql-core";
export const users = mysqlTable(
"users",
{
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
fullName: varchar("full_name", { length: 256 }),
},
(users) => ({
nameIdx: index("name_idx").on(users.fullName),
})
);
export const emails = mysqlTable("email", {
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
phone: varchar("phone", { length: 256 }),
userId: int("user_id").references(() => users.id),
});

View File

@ -0,0 +1,16 @@
// drizzle.config.ts
import "dotenv/config";
import type { Config } from "drizzle-kit";
export default {
schema: "./db/schema.ts",
out: "./drizzle/migrations",
driver: "mysql2", // 'pg' | 'mysql2' | 'better-sqlite' | 'libsql' | 'turso'
dbCredentials: {
host: process.env.DB_HOST!,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME!,
},
} satisfies Config;

View File

@ -0,0 +1,27 @@
CREATE TABLE `email`
(
`id` bigint AUTO_INCREMENT NOT NULL,
`phone` varchar
(256),
`user_id` int,
CONSTRAINT `email_id` PRIMARY KEY
(`id`)
);
--> statement-breakpoint
CREATE TABLE `users`
(
`id` bigint AUTO_INCREMENT NOT NULL,
`full_name` varchar
(256),
CONSTRAINT `users_id` PRIMARY KEY
(`id`)
);
--> statement-breakpoint
CREATE INDEX `name_idx` ON `users`
(`full_name`);--> statement-breakpoint
ALTER TABLE `email`
ADD CONSTRAINT `email_user_id_users_id_fk` FOREIGN KEY
(`user_id`) REFERENCES `users`
(`id`) ON
DELETE no action ON
UPDATE no action;

View File

@ -0,0 +1,103 @@
{
"version": "5",
"dialect": "mysql",
"id": "9edb1131-47b9-43e7-9252-e68e1e3dc66f",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"email": {
"name": "email",
"columns": {
"id": {
"name": "id",
"type": "bigint",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"phone": {
"name": "phone",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"email_user_id_users_id_fk": {
"name": "email_user_id_users_id_fk",
"tableFrom": "email",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"email_id": {
"name": "email_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "bigint",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"full_name": {
"name": "full_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"name_idx": {
"name": "name_idx",
"columns": [
"full_name"
],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {
"users_id": {
"name": "users_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View File

@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "mysql",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1701338981518,
"tag": "0000_charming_blindfold",
"breakpoints": true
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -9,12 +9,15 @@
"lint": "next lint"
},
"dependencies": {
"@planetscale/database": "^1.11.0",
"@radix-ui/react-slot": "^1.0.2",
"@react-google-maps/api": "^2.19.2",
"class-variance-authority": "^0.7.0",
"classnames": "^2.3.2",
"clsx": "^2.0.0",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.29.1",
"easymde": "^2.18.0",
"embla-carousel-auto-height": "^8.0.0-rc14",
"embla-carousel-autoplay": "^8.0.0-rc14",
@ -39,6 +42,7 @@
"@types/react-dom": "^18",
"autoprefixer": "^10",
"daisyui": "^3.9.3",
"drizzle-kit": "^0.20.6",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"postcss": "^8",

View File

@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2022",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,