{
  "slug": "pg-drizzle",
  "runtimes": {
    "node": {
      "frameworks": {
        "express": {
          "dependencies": {
            "runtime": [
              "drizzle-orm",
              "pg"
            ],
            "dev": [
              "drizzle-kit",
              "@types/pg"
            ]
          },
          "env": [
            "DATABASE_URL",
            "NODE_ENV"
          ],
          "architectures": {
            "mvc": {
              "files": [
                {
                  "type": "file",
                  "path": "drizzle.config.ts",
                  "content": "import { defineConfig } from \"drizzle-kit\";\r\nimport { env } from \"./src/configs/env\";\r\n\r\nexport default defineConfig({\r\n  out: \"./migrations\",\r\n  schema: \"./src/db/index.ts\",\r\n  dialect: \"postgresql\",\r\n  dbCredentials: {\r\n    url: env.DATABASE_URL\r\n  },\r\n  verbose: true,\r\n  strict: true\r\n});\r\n"
                },
                {
                  "type": "file",
                  "path": "migrations/.gitkeep",
                  "content": ""
                },
                {
                  "type": "file",
                  "path": "src/db/index.ts",
                  "content": "//? Export all schemas from schemas directory\r\n\r\nexport * from \"./schemas/user.schema\";\r\n"
                },
                {
                  "type": "file",
                  "path": "src/configs/env.ts",
                  "content": "import dotenv from \"dotenv-flow\";\r\ndotenv.config();\r\nimport { z } from \"zod\";\r\n\r\nexport const envSchema = z.object({\r\n  NODE_ENV: z\r\n    .enum([\"development\", \"test\", \"production\"])\r\n    .default(\"development\"),\r\n\r\n  DATABASE_URL: z.url()\r\n});\r\n\r\nexport type Env = z.infer<typeof envSchema>;\r\n\r\nconst result = envSchema.safeParse(process.env);\r\n\r\nif (!result.success) {\r\n  console.error(\"❌ Invalid environment configuration\");\r\n  console.error(z.prettifyError(result.error));\r\n  process.exit(1);\r\n}\r\n\r\nexport const env: Readonly<Env> = Object.freeze(result.data);\r\n\r\nexport default env;\r\n"
                },
                {
                  "type": "file",
                  "path": "src/configs/db.ts",
                  "content": "import { drizzle } from \"drizzle-orm/node-postgres\";\r\nimport env from \"./env\";\r\n\r\nconst db = drizzle(env.DATABASE_URL!, {\r\n  logger: env.NODE_ENV === \"development\"\r\n});\r\n\r\nexport default db;\r\n\r\n/**\r\n * ? Usage:\r\n *  await db.insert(usersTable).values(user);\r\n */\r\n"
                },
                {
                  "type": "file",
                  "path": "src/db/schemas/user.schema.ts",
                  "content": "import { integer, pgTable, varchar } from \"drizzle-orm/pg-core\";\r\n\r\nexport const usersTable = pgTable(\"users\", {\r\n  id: integer().primaryKey().generatedAlwaysAsIdentity(),\r\n  name: varchar({ length: 255 }).notNull(),\r\n  age: integer().notNull(),\r\n  email: varchar({ length: 255 }).notNull().unique()\r\n});\r\n\r\nexport type User = typeof usersTable.$inferSelect;\r\nexport type NewUser = typeof usersTable.$inferInsert;\r\n"
                }
              ]
            },
            "feature": {
              "files": [
                {
                  "type": "file",
                  "path": "drizzle.config.ts",
                  "content": "import { defineConfig } from \"drizzle-kit\";\r\nimport { env } from \"./src/shared/configs/env\";\r\n\r\nexport default defineConfig({\r\n  out: \"./migrations\",\r\n  schema: \"./src/db/index.ts\",\r\n  dialect: \"postgresql\",\r\n  dbCredentials: {\r\n    url: env.DATABASE_URL\r\n  },\r\n  verbose: true,\r\n  strict: true\r\n});\r\n"
                },
                {
                  "type": "file",
                  "path": "migrations/.gitkeep",
                  "content": ""
                },
                {
                  "type": "file",
                  "path": "src/db/index.ts",
                  "content": "//? Export all schemas from schemas directory\r\n\r\nexport * from \"./schemas/user.schema\";\r\n"
                },
                {
                  "type": "file",
                  "path": "src/shared/configs/env.ts",
                  "content": "import dotenv from \"dotenv-flow\";\r\ndotenv.config();\r\nimport { z } from \"zod\";\r\n\r\nexport const envSchema = z.object({\r\n  NODE_ENV: z\r\n    .enum([\"development\", \"test\", \"production\"])\r\n    .default(\"development\"),\r\n\r\n  DATABASE_URL: z.url()\r\n});\r\n\r\nexport type Env = z.infer<typeof envSchema>;\r\n\r\nconst result = envSchema.safeParse(process.env);\r\n\r\nif (!result.success) {\r\n  console.error(\"❌ Invalid environment configuration\");\r\n  console.error(z.prettifyError(result.error));\r\n  process.exit(1);\r\n}\r\n\r\nexport const env: Readonly<Env> = Object.freeze(result.data);\r\n\r\nexport default env;\r\n"
                },
                {
                  "type": "file",
                  "path": "src/shared/configs/db.ts",
                  "content": "import { drizzle } from \"drizzle-orm/node-postgres\";\r\nimport env from \"./env\";\r\n\r\nconst db = drizzle(env.DATABASE_URL!, {\r\n  logger: env.NODE_ENV === \"development\"\r\n});\r\n\r\nexport default db;\r\n\r\n/**\r\n * ? Usage:\r\n *  await db.insert(usersTable).values(user);\r\n */\r\n"
                },
                {
                  "type": "file",
                  "path": "src/db/schemas/user.schema.ts",
                  "content": "import { integer, pgTable, varchar } from \"drizzle-orm/pg-core\";\r\n\r\nexport const usersTable = pgTable(\"users\", {\r\n  id: integer().primaryKey().generatedAlwaysAsIdentity(),\r\n  name: varchar({ length: 255 }).notNull(),\r\n  age: integer().notNull(),\r\n  email: varchar({ length: 255 }).notNull().unique()\r\n});\r\n\r\nexport type User = typeof usersTable.$inferSelect;\r\nexport type NewUser = typeof usersTable.$inferInsert;\r\n"
                }
              ]
            }
          }
        },
        "nextjs": {
          "dependencies": {
            "runtime": [
              "drizzle-orm",
              "pg"
            ],
            "dev": [
              "drizzle-kit",
              "@types/pg"
            ]
          },
          "env": [
            "DATABASE_URL",
            "NODE_ENV"
          ],
          "architectures": {
            "file-api": {
              "files": [
                {
                  "type": "file",
                  "path": "drizzle.config.ts",
                  "content": "import { defineConfig } from \"drizzle-kit\";\r\n\r\nexport default defineConfig({\r\n  out: \"./migrations\",\r\n  schema: \"./src/db/index.ts\",\r\n  dialect: \"postgresql\",\r\n  dbCredentials: {\r\n    url: process.env.DATABASE_URL!\r\n  },\r\n  verbose: true,\r\n  strict: true\r\n});\r\n\r\n/**\r\n *? Add the following scripts to your package.json:\r\n *\r\n * 1. \"db:generate\": \"drizzle-kit generate\" //* Generate migration files\r\n * 2. \"db:migrate\": \"drizzle-kit migrate\"   //* Apply migrations to the database\r\n * 3. \"db:studio\": \"drizzle-kit studio\"     //* Open Drizzle Studio\r\n\r\n * 4. \"db:push\": \"npx drizzle-kit push\"  //* You can directly apply changes to your database using this command.\r\n **/\r\n"
                },
                {
                  "type": "file",
                  "path": "migrations/.gitkeep",
                  "content": ""
                },
                {
                  "type": "file",
                  "path": "src/db/index.ts",
                  "content": "//? Export all schemas from ./schemas directory\r\nexport * from \"./schemas/user.schema\";\r\n"
                },
                {
                  "type": "file",
                  "path": "src/db/connection.ts",
                  "content": "import { drizzle } from \"drizzle-orm/node-postgres\";\r\n\r\nconst db = drizzle(process.env.DATABASE_URL!, {\r\n  logger: process.env.NODE_ENV === \"development\"\r\n});\r\n\r\nexport default db;"
                },
                {
                  "type": "file",
                  "path": "src/db/schemas/user.schema.ts",
                  "content": "import { integer, pgTable, varchar } from \"drizzle-orm/pg-core\";\r\n\r\nexport const usersTable = pgTable(\"users_table\", {\r\n  id: integer().primaryKey().generatedAlwaysAsIdentity(),\r\n  name: varchar({ length: 255 }).notNull(),\r\n  age: integer().notNull(),\r\n  email: varchar({ length: 255 }).notNull().unique()\r\n});\r\n"
                }
              ]
            }
          }
        }
      }
    }
  }
}
