diff --git a/drizzle.config.ts b/drizzle.config.ts index ce53326..fa188fc 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -11,6 +11,7 @@ export default defineConfig({ schema: "./src/config/db/schema.mts", out: "./drizzle", dialect: "postgresql", + casing: "snake_case", dbCredentials: { url: DB_URL, }, diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index bedc3e3..b3811f6 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -31,4 +31,4 @@ "breakpoints": true } ] -} \ No newline at end of file +} diff --git a/package.json b/package.json index 7e3e37f..aa19635 100644 --- a/package.json +++ b/package.json @@ -21,19 +21,21 @@ "build:code": "tsc && tsc-alias", "build": "pnpm run build:kill-dist && pnpm run build:code", "postbuild": "node postbuild.mjs", - "db:explorer": "drizzle-kit studio", - "db:migrate-generate": "drizzle-kit generate", - "db:migrate-run": "drizzle-kit migrate" + "db:studio": "drizzle-kit studio", + "db:generate": "drizzle-kit generate", + "db:migrate": "drizzle-kit migrate", + "db:check": "drizzle-kit check", + "db:up": "drizzle-kit up" }, "devDependencies": { "@types/node": "^20.14.8", + "@types/pg": "^8.11.10", "@typescript-eslint/eslint-plugin": "^6.18.0", "@typescript-eslint/parser": "^6.18.0", - "drizzle-kit": "^0.22.8", + "drizzle-kit": "^0.27.1", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.2", - "pg": "^8.12.0", "prettier": "^3.3.2", "rimraf": "^5.0.7", "tsc-alias": "^1.8.10", @@ -48,11 +50,11 @@ "@scalar/hono-api-reference": "^0.5.92", "arctic": "^1.9.1", "dotenv": "^16.4.5", - "drizzle-orm": "^0.31.2", + "drizzle-orm": "^0.36.0", "hono": "^4.4.11", "hono-rate-limiter": "^0.4.0", "lucia": "^3.2.0", - "postgres": "^3.4.4", + "pg": "^8.13.1", "zod": "^3.23.8" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5464f4..400bd76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,8 +24,8 @@ importers: specifier: ^16.4.5 version: 16.4.5 drizzle-orm: - specifier: ^0.31.2 - version: 0.31.2(pg@8.12.0)(postgres@3.4.4) + specifier: ^0.36.0 + version: 0.36.0(@types/pg@8.11.10)(pg@8.13.1)(postgres@3.4.4) hono: specifier: ^4.4.11 version: 4.4.11 @@ -35,9 +35,9 @@ importers: lucia: specifier: ^3.2.0 version: 3.2.0 - postgres: - specifier: ^3.4.4 - version: 3.4.4 + pg: + specifier: ^8.13.1 + version: 8.13.1 zod: specifier: ^3.23.8 version: 3.23.8 @@ -45,6 +45,9 @@ importers: '@types/node': specifier: ^20.14.8 version: 20.14.8 + '@types/pg': + specifier: ^8.11.10 + version: 8.11.10 '@typescript-eslint/eslint-plugin': specifier: ^6.18.0 version: 6.18.0(@typescript-eslint/parser@6.18.0(eslint@8.56.0)(typescript@5.5.2))(eslint@8.56.0)(typescript@5.5.2) @@ -52,8 +55,8 @@ importers: specifier: ^6.18.0 version: 6.18.0(eslint@8.56.0)(typescript@5.5.2) drizzle-kit: - specifier: ^0.22.8 - version: 0.22.8 + specifier: ^0.27.1 + version: 0.27.1 eslint: specifier: ^8.56.0 version: 8.56.0 @@ -63,9 +66,6 @@ importers: eslint-plugin-prettier: specifier: ^5.1.2 version: 5.1.2(eslint-config-prettier@9.1.0(eslint@8.56.0))(eslint@8.56.0)(prettier@3.3.2) - pg: - specifier: ^8.12.0 - version: 8.12.0 prettier: specifier: ^3.3.2 version: 3.3.2 @@ -171,6 +171,9 @@ packages: '@codemirror/view@6.28.4': resolution: {integrity: sha512-QScv95fiviSQ/CaVGflxAvvvDy/9wi0RFyDl4LkHHWiMr/UPebyuTspmYSeN5Nx6eujcPYwsQzA6ZIZucKZVHQ==} + '@drizzle-team/brocli@0.10.2': + resolution: {integrity: sha512-z33Il7l5dKjUgGULTqBsQBQwckHh5AbIuxhdsIxDDiZAzBOrZO6q9ogcWC65kU382AfynTfgNumVcNIjuIua6w==} + '@emnapi/core@0.45.0': resolution: {integrity: sha512-DPWjcUDQkCeEM4VnljEOEcXdAD7pp8zSZsgOujk/LGIwCXWbXJngin+MO4zbH429lzeC3WbYLGjE2MaUOwzpyw==} @@ -179,9 +182,11 @@ packages: '@esbuild-kit/core-utils@3.1.0': resolution: {integrity: sha512-Uuk8RpCg/7fdHSceR1M6XbSZFSuMrxcePFuGgyvsBn+u339dk5OeL4jv2EojwTN2st/unJGsVm4qHWjWNmJ/tw==} + deprecated: 'Merged into tsx: https://tsx.is' '@esbuild-kit/esm-loader@2.5.5': resolution: {integrity: sha512-Qwfvj/qoPbClxCRNuac1Du01r9gvNOT+pMYtJDapfB1eoGN1YlJ1BixLyL9WVENRx5RXgNLdfYdx/CuswlGhMw==} + deprecated: 'Merged into tsx: https://tsx.is' '@esbuild/aix-ppc64@0.19.11': resolution: {integrity: sha512-FnzU0LyE3ySQk7UntJO4+qIiQgI7KoODnZg5xzXIrFJlKd2P2gwHsHY4927xj9y5PJmJSzULiUCWmv7iWnNa7g==} @@ -1188,6 +1193,9 @@ packages: '@types/node@20.14.8': resolution: {integrity: sha512-DO+2/jZinXfROG7j7WKFn/3C6nFwxy2lLpgLjEXJz+0XKphZlTLJ14mo8Vfg8X5BWN6XjyESXq+LcYdT7tR3bA==} + '@types/pg@8.11.10': + resolution: {integrity: sha512-LczQUW4dbOQzsH2RQ5qoeJ6qJPdrcM/DcMLoqWQkMLMsq83J5lAX3LXjdkWdpscFy67JSOWDnh7Ny/sPFykmkg==} + '@types/qs@6.9.15': resolution: {integrity: sha512-uXHQKES6DQKKCLh441Xv/dwxOq1TVS3JPUMlEqoEglvlhR6Mxnlew/Xq/LRVHpLyk7iK3zODe1qYHIMltO7XGg==} @@ -1682,21 +1690,23 @@ packages: resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} engines: {node: '>=12'} - drizzle-kit@0.22.8: - resolution: {integrity: sha512-VjI4wsJjk3hSqHSa3TwBf+uvH6M6pRHyxyoVbt935GUzP9tUR/BRZ+MhEJNgryqbzN2Za1KP0eJMTgKEPsalYQ==} + drizzle-kit@0.27.1: + resolution: {integrity: sha512-4BNA0T2blN+jW5wSwhtc+FIlCMuxYSMWCnYYdOBi5rttwq8aVXRUid0d0NCzcBKtZQSPZGAUxy+TXr7Q1OgEug==} hasBin: true - drizzle-orm@0.31.2: - resolution: {integrity: sha512-QnenevbnnAzmbNzQwbhklvIYrDE8YER8K7kSrAWQSV1YvFCdSQPzj+jzqRdTSsV2cDqSpQ0NXGyL1G9I43LDLg==} + drizzle-orm@0.36.0: + resolution: {integrity: sha512-6BETYPdKSR7cDHC0ZfqZk2VrKJ8n/Rfd3ajFPsAbc69gi87nwZ6oBA2wUGMELHA0tQE4kUKN0Ds00LUZQ6Z69A==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' '@cloudflare/workers-types': '>=3' - '@electric-sql/pglite': '>=0.1.1' - '@libsql/client': '*' + '@electric-sql/pglite': '>=0.2.0' + '@libsql/client': '>=0.10.0' + '@libsql/client-wasm': '>=0.10.0' '@neondatabase/serverless': '>=0.1' '@op-engineering/op-sqlite': '>=2' '@opentelemetry/api': ^1.4.1 '@planetscale/database': '>=1' + '@prisma/client': '*' '@tidbcloud/serverless': '*' '@types/better-sqlite3': '*' '@types/pg': '*' @@ -1712,6 +1722,7 @@ packages: mysql2: '>=2' pg: '>=8' postgres: '>=3' + prisma: '*' react: '>=18' sql.js: '>=1' sqlite3: '>=5' @@ -1724,6 +1735,8 @@ packages: optional: true '@libsql/client': optional: true + '@libsql/client-wasm': + optional: true '@neondatabase/serverless': optional: true '@op-engineering/op-sqlite': @@ -1732,6 +1745,8 @@ packages: optional: true '@planetscale/database': optional: true + '@prisma/client': + optional: true '@tidbcloud/serverless': optional: true '@types/better-sqlite3': @@ -1762,6 +1777,8 @@ packages: optional: true postgres: optional: true + prisma: + optional: true react: optional: true sql.js: @@ -2642,6 +2659,9 @@ packages: resolution: {integrity: sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==} engines: {node: '>= 0.4'} + obuf@1.1.2: + resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==} + once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} @@ -2715,27 +2735,38 @@ packages: pg-cloudflare@1.1.1: resolution: {integrity: sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==} - pg-connection-string@2.6.4: - resolution: {integrity: sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA==} + pg-connection-string@2.7.0: + resolution: {integrity: sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==} pg-int8@1.0.1: resolution: {integrity: sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==} engines: {node: '>=4.0.0'} - pg-pool@3.6.2: - resolution: {integrity: sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==} + pg-numeric@1.0.2: + resolution: {integrity: sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==} + engines: {node: '>=4'} + + pg-pool@3.7.0: + resolution: {integrity: sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==} peerDependencies: pg: '>=8.0' pg-protocol@1.6.1: resolution: {integrity: sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==} + pg-protocol@1.7.0: + resolution: {integrity: sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==} + pg-types@2.2.0: resolution: {integrity: sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==} engines: {node: '>=4'} - pg@8.12.0: - resolution: {integrity: sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==} + pg-types@4.0.2: + resolution: {integrity: sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==} + engines: {node: '>=10'} + + pg@8.13.1: + resolution: {integrity: sha512-OUir1A0rPNZlX//c7ksiu7crsGZTKSOXJPgtNiHGIlC9H0lO+NC6ZDYksSgBYY/thSWhnSRBv8w1lieNNGATNQ==} engines: {node: '>= 8.0.0'} peerDependencies: pg-native: '>=3.0.1' @@ -2817,18 +2848,37 @@ packages: resolution: {integrity: sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==} engines: {node: '>=4'} + postgres-array@3.0.2: + resolution: {integrity: sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==} + engines: {node: '>=12'} + postgres-bytea@1.0.0: resolution: {integrity: sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==} engines: {node: '>=0.10.0'} + postgres-bytea@3.0.0: + resolution: {integrity: sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==} + engines: {node: '>= 6'} + postgres-date@1.0.7: resolution: {integrity: sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==} engines: {node: '>=0.10.0'} + postgres-date@2.1.0: + resolution: {integrity: sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==} + engines: {node: '>=12'} + postgres-interval@1.2.0: resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==} engines: {node: '>=0.10.0'} + postgres-interval@3.0.0: + resolution: {integrity: sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==} + engines: {node: '>=12'} + + postgres-range@1.1.4: + resolution: {integrity: sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==} + postgres@3.4.4: resolution: {integrity: sha512-IbyN+9KslkqcXa8AO9fxpk97PA4pzewvpi2B3Dwy9u4zpV32QicaEdgmF3eSQUzdRk7ttDHQejNgAEr4XoeH4A==} engines: {node: '>=12'} @@ -3578,6 +3628,8 @@ snapshots: style-mod: 4.1.2 w3c-keyname: 2.2.8 + '@drizzle-team/brocli@0.10.2': {} + '@emnapi/core@0.45.0': dependencies: tslib: 2.6.2 @@ -4568,6 +4620,12 @@ snapshots: dependencies: undici-types: 5.26.5 + '@types/pg@8.11.10': + dependencies: + '@types/node': 20.14.8 + pg-protocol: 1.6.1 + pg-types: 4.0.2 + '@types/qs@6.9.15': {} '@types/range-parser@1.2.7': {} @@ -5148,17 +5206,19 @@ snapshots: dotenv@16.4.5: {} - drizzle-kit@0.22.8: + drizzle-kit@0.27.1: dependencies: + '@drizzle-team/brocli': 0.10.2 '@esbuild-kit/esm-loader': 2.5.5 esbuild: 0.19.11 esbuild-register: 3.5.0(esbuild@0.19.11) transitivePeerDependencies: - supports-color - drizzle-orm@0.31.2(pg@8.12.0)(postgres@3.4.4): + drizzle-orm@0.36.0(@types/pg@8.11.10)(pg@8.13.1)(postgres@3.4.4): optionalDependencies: - pg: 8.12.0 + '@types/pg': 8.11.10 + pg: 8.13.1 postgres: 3.4.4 eastasianwidth@0.2.0: {} @@ -6317,6 +6377,8 @@ snapshots: has-symbols: 1.0.3 object-keys: 1.1.1 + obuf@1.1.2: {} + once@1.4.0: dependencies: wrappy: 1.0.2 @@ -6385,16 +6447,20 @@ snapshots: pg-cloudflare@1.1.1: optional: true - pg-connection-string@2.6.4: {} + pg-connection-string@2.7.0: {} pg-int8@1.0.1: {} - pg-pool@3.6.2(pg@8.12.0): + pg-numeric@1.0.2: {} + + pg-pool@3.7.0(pg@8.13.1): dependencies: - pg: 8.12.0 + pg: 8.13.1 pg-protocol@1.6.1: {} + pg-protocol@1.7.0: {} + pg-types@2.2.0: dependencies: pg-int8: 1.0.1 @@ -6403,11 +6469,21 @@ snapshots: postgres-date: 1.0.7 postgres-interval: 1.2.0 - pg@8.12.0: + pg-types@4.0.2: dependencies: - pg-connection-string: 2.6.4 - pg-pool: 3.6.2(pg@8.12.0) - pg-protocol: 1.6.1 + pg-int8: 1.0.1 + pg-numeric: 1.0.2 + postgres-array: 3.0.2 + postgres-bytea: 3.0.0 + postgres-date: 2.1.0 + postgres-interval: 3.0.0 + postgres-range: 1.1.4 + + pg@8.13.1: + dependencies: + pg-connection-string: 2.7.0 + pg-pool: 3.7.0(pg@8.13.1) + pg-protocol: 1.7.0 pg-types: 2.2.0 pgpass: 1.0.5 optionalDependencies: @@ -6476,15 +6552,28 @@ snapshots: postgres-array@2.0.0: {} + postgres-array@3.0.2: {} + postgres-bytea@1.0.0: {} + postgres-bytea@3.0.0: + dependencies: + obuf: 1.1.2 + postgres-date@1.0.7: {} + postgres-date@2.1.0: {} + postgres-interval@1.2.0: dependencies: xtend: 4.0.2 - postgres@3.4.4: {} + postgres-interval@3.0.0: {} + + postgres-range@1.1.4: {} + + postgres@3.4.4: + optional: true prelude-ls@1.2.1: {} diff --git a/src/config/db/drizzle.mts b/src/config/db/drizzle.mts index 85b70a9..11142f5 100644 --- a/src/config/db/drizzle.mts +++ b/src/config/db/drizzle.mts @@ -1,8 +1,11 @@ -import { drizzle } from "drizzle-orm/postgres-js"; -import postgres from "postgres"; +import { drizzle } from "drizzle-orm/node-postgres"; import { env } from "@/config/env.mjs"; import * as schema from "./schema.mjs"; -const client = postgres(env.DATABASE_URL); -export const db = drizzle(client, { schema, logger: true }); +export const db = drizzle({ + connection: env.DATABASE_URL, + schema, + logger: !(env.NODE_ENV === "production"), + casing: "snake_case", +}); diff --git a/src/config/db/schema.mts b/src/config/db/schema.mts index facadf4..ff36a50 100644 --- a/src/config/db/schema.mts +++ b/src/config/db/schema.mts @@ -4,25 +4,23 @@ import { boolean, index, jsonb, pgTable, primaryKey, text, timestamp } from "dri export const logs = pgTable( "logs", { - id: text("id").primaryKey().notNull(), - action: text("action").notNull(), - environment: text("environment").notNull(), - ip: text("ip"), - data: jsonb("data"), - createdAt: timestamp("created_at", { precision: 3, mode: "string" }).defaultNow().notNull(), - serviceId: text("service_id") + id: text().primaryKey().notNull(), + action: text().notNull(), + environment: text().notNull(), + ip: text(), + data: jsonb(), + createdAt: timestamp({ precision: 3, mode: "string" }).defaultNow().notNull(), + serviceId: text() .notNull() .references(() => services.id, { onDelete: "cascade", onUpdate: "cascade" }), - level: text("level").default("info").notNull(), - lookupFilterValue: text("lookup_filter_value"), - isPersisted: boolean("is_persisted").notNull(), - }, - (table) => { - return { - createdAtIdx: index("log_created_at_idx").on(table.createdAt), - levelIdx: index("log_level_idx").on(table.level), - }; + level: text().default("info").notNull(), + lookupFilterValue: text(), + isPersisted: boolean().notNull(), }, + (t) => ({ + createdAtIdx: index("log_created_at_idx").on(t.createdAt), + levelIdx: index("log_level_idx").on(t.level), + }), ); export const logRelations = relations(logs, ({ one }) => ({ @@ -35,20 +33,18 @@ export const logRelations = relations(logs, ({ one }) => ({ export const services = pgTable( "services", { - id: text("id").primaryKey().notNull(), - name: text("name").notNull(), - isActive: boolean("is_active").notNull(), - createdAt: timestamp("created_at", { precision: 3, mode: "string" }).defaultNow().notNull(), - isPersisted: boolean("is_persisted").notNull(), - isAdmin: boolean("is_admin").notNull(), - tenantId: text("tenant_id").references(() => tenants.id), - }, - (table) => { - return { - createdAtIdx: index("service_created_at_idx").on(table.createdAt), - serviceTenantIdx: index("service_tenant_idx").on(table.tenantId), - }; + id: text().primaryKey().notNull(), + name: text().notNull(), + isActive: boolean().notNull(), + createdAt: timestamp({ precision: 3, mode: "string" }).defaultNow().notNull(), + isPersisted: boolean().notNull(), + isAdmin: boolean().notNull(), + tenantId: text().references(() => tenants.id), }, + (t) => ({ + createdAtIdx: index("service_created_at_idx").on(t.createdAt), + serviceTenantIdx: index("service_tenant_idx").on(t.tenantId), + }), ); export const serviceRelations = relations(services, ({ many, one }) => ({ @@ -60,11 +56,11 @@ export const serviceRelations = relations(services, ({ many, one }) => ({ })); export const tenants = pgTable("tenants", { - id: text("id").primaryKey().notNull(), - name: text("name").notNull(), - workspace: text("workspace").notNull().unique(), - createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(), + id: text().primaryKey().notNull(), + name: text().notNull(), + workspace: text().notNull().unique(), + createdAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(), + updatedAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(), }); export const tenantRelations = relations(tenants, ({ many }) => ({ @@ -73,11 +69,11 @@ export const tenantRelations = relations(tenants, ({ many }) => ({ })); export const users = pgTable("users", { - id: text("id").primaryKey().notNull(), - username: text("username").notNull(), + id: text().primaryKey().notNull(), + username: text().notNull(), githubId: text("github_id").unique(), - createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(), + createdAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(), + updatedAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(), }); export const userRelations = relations(users, ({ many }) => ({ @@ -88,13 +84,13 @@ export const userRelations = relations(users, ({ many }) => ({ export const usersToTenants = pgTable( "users_to_tenants", { - userId: text("user_id") + userId: text() .notNull() .references(() => users.id, { onDelete: "cascade", onUpdate: "cascade", }), - tenantId: text("tenant_id") + tenantId: text() .notNull() .references(() => tenants.id, { onDelete: "cascade", @@ -118,15 +114,15 @@ export const usersToTenantsRelations = relations(usersToTenants, ({ one }) => ({ })); export const sessions = pgTable("sessions", { - id: text("id").primaryKey().notNull(), - userId: text("user_id") + id: text().primaryKey().notNull(), + userId: text() .notNull() .references(() => users.id, { onDelete: "cascade", onUpdate: "cascade" }), - expiresAt: timestamp("expires_at", { + expiresAt: timestamp({ withTimezone: true, mode: "date", }).notNull(), - createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(), + createdAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(), }); export const sessionRelations = relations(sessions, ({ one }) => ({