PlanetScale DB 하나로 수많은 프로젝트 호스팅
이미 인수된 기업의 제품을 쓰는 것을 안 좋아하기도 해서, 최근 대부분의 프로젝트 및 앞으로 프로젝트를 PlanetScale DB로 옮기려고 했다. 영속적인 기업을 만들고자 하는 철학이 마음에 들기도 했고, 장기적으로 PlanetScale을 쓰는 것을 연습해야겠다고 생각하기도 했고. 아무튼 다음은 PlanetScale DB 하나로 많은 프로젝트를 호스팅하는 방법이다.
typescript
// src/db/schema.tsimport { pgSchema, text, timestamp, uuid } from 'drizzle-orm/pg-core'
// Define a schema for the project (not Postgres's default public)export const myProject = pgSchema('my_project')
// Create all tables under this schemaexport const users = myProject.table('users', { id: uuid('id').defaultRandom().primaryKey(), name: text('name').notNull(), createdAt: timestamp('created_at').notNull().defaultNow(),})
export type User = typeof users.$inferSelecttypescript
// drizzle.config.tsimport { defineConfig } from 'drizzle-kit'
export default defineConfig({ schema: './src/db/schema.ts', out: './drizzle', dialect: 'postgresql', dbCredentials: { url: process.env.DATABASE_URL!, }, // Isolate the schema with the project codename schemaFilter: ['my_project'], // Save the migration to the schema of the project codename migrations: { schema: 'my_project', table: '__drizzle_migrations', },})typescript
// src/db/index.tsimport { drizzle } from 'drizzle-orm/node-postgres'import * as schema from './schema'
export const db = drizzle(process.env.DATABASE_URL!, { schema })