From 41af1e45a860844014f601a97311a78f05591d3b Mon Sep 17 00:00:00 2001 From: tangoyankee Date: Tue, 12 Nov 2024 15:36:23 -0500 Subject: [PATCH] upgrade drizzle-kit and drizzle-orm drizzle-orm: 0.31.1 -> 0.36.1 drizzle-kit: 0.22.2 -> 0.28.0 refactor deprecated methods and objects closes #386 --- drizzle.config.ts | 6 ++--- package-lock.json | 32 +++++++++++++++++-------- package.json | 6 ++--- src/drizzle-pgis/index.ts | 2 -- src/drizzle-pgis/spatial-type.ts | 23 ------------------ src/schema/budget-line.ts | 6 +---- src/schema/capital-commitment.ts | 22 ++++++++--------- src/schema/capital-project-checkbook.ts | 16 ++++++------- src/schema/capital-project-fund.ts | 16 ++++++------- src/schema/capital-project.ts | 16 ++++++------- src/schema/city-council-district.ts | 12 ++++------ src/schema/community-district.ts | 14 +++++------ 12 files changed, 71 insertions(+), 100 deletions(-) delete mode 100644 src/drizzle-pgis/spatial-type.ts diff --git a/drizzle.config.ts b/drizzle.config.ts index b5345ce0..90be2472 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,7 +1,7 @@ // Drizzle kit configuration -import type { Config } from "drizzle-kit"; +import { defineConfig } from "drizzle-kit"; -export default { +export default defineConfig({ schema: "./src/schema/*", dialect: "postgresql", out: "db/migration", @@ -15,4 +15,4 @@ export default { rejectUnauthorized: false, }, }, -} satisfies Config; +}); diff --git a/package-lock.json b/package-lock.json index 276f2558..588779fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.4.5", "@nestjs/serve-static": "^4.0.0", - "drizzle-orm": "^0.31.1", + "drizzle-orm": "^0.36.1", "immer": "^10.1.1", "joi": "^17.11.0", "pg": "^8.11.3", @@ -44,7 +44,7 @@ "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", "dotenv": "^16.3.1", - "drizzle-kit": "^0.22.2", + "drizzle-kit": "^0.28.0", "esbuild": "^0.21.2", "eslint": "^8.42.0", "eslint-config-prettier": "^9.0.0", @@ -1126,6 +1126,13 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@drizzle-team/brocli": { + "version": "0.10.2", + "resolved": "https://registry.npmjs.org/@drizzle-team/brocli/-/brocli-0.10.2.tgz", + "integrity": "sha512-z33Il7l5dKjUgGULTqBsQBQwckHh5AbIuxhdsIxDDiZAzBOrZO6q9ogcWC65kU382AfynTfgNumVcNIjuIua6w==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/@emotion/is-prop-valid": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.2.2.tgz", @@ -7558,12 +7565,13 @@ } }, "node_modules/drizzle-kit": { - "version": "0.22.8", - "resolved": "https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-0.22.8.tgz", - "integrity": "sha512-VjI4wsJjk3hSqHSa3TwBf+uvH6M6pRHyxyoVbt935GUzP9tUR/BRZ+MhEJNgryqbzN2Za1KP0eJMTgKEPsalYQ==", + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-0.28.0.tgz", + "integrity": "sha512-KqI+CS2Ga9GYIrXpxpCDUJJrH/AT/k4UY0Pb4oRgQEGkgN1EdCnqp664cXgwPWjDr5RBtTsjZipw8+8C//K63A==", "dev": true, "license": "MIT", "dependencies": { + "@drizzle-team/brocli": "^0.10.2", "@esbuild-kit/esm-loader": "^2.5.5", "esbuild": "^0.19.7", "esbuild-register": "^3.5.0" @@ -8003,15 +8011,16 @@ } }, "node_modules/drizzle-orm": { - "version": "0.31.4", - "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.31.4.tgz", - "integrity": "sha512-VGD9SH9aStF2z4QOTnVlVX/WghV/EnuEzTmsH3fSVp2E4fFgc8jl3viQrS/XUJx1ekW4rVVLJMH42SfGQdjX3Q==", + "version": "0.36.1", + "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.36.1.tgz", + "integrity": "sha512-F4hbimnMEhyWzDowQB4xEuVJJWXLHZYD7FYwvo8RImY+N7pStGqsbfmT95jDbec1s4qKmQbiuxEDZY90LRrfIw==", "license": "Apache-2.0", "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", @@ -8049,6 +8058,9 @@ "@libsql/client": { "optional": true }, + "@libsql/client-wasm": { + "optional": true + }, "@neondatabase/serverless": { "optional": true }, diff --git a/package.json b/package.json index a821a1a8..48d6ad1e 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.4.5", "@nestjs/serve-static": "^4.0.0", - "drizzle-orm": "^0.31.1", + "drizzle-orm": "^0.36.1", "immer": "^10.1.1", "joi": "^17.11.0", "pg": "^8.11.3", @@ -64,7 +64,7 @@ "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", "dotenv": "^16.3.1", - "drizzle-kit": "^0.22.2", + "drizzle-kit": "^0.28.0", "esbuild": "^0.21.2", "eslint": "^8.42.0", "eslint-config-prettier": "^9.0.0", @@ -112,4 +112,4 @@ "npm run lint" ] } -} \ No newline at end of file +} diff --git a/src/drizzle-pgis/index.ts b/src/drizzle-pgis/index.ts index 9449a7e3..180e41f0 100644 --- a/src/drizzle-pgis/index.ts +++ b/src/drizzle-pgis/index.ts @@ -21,5 +21,3 @@ export { multiPolygonGeog, geometryCollectionGeog, } from "./geography"; - -export { ST_AsGeoJSON } from "./spatial-type"; diff --git a/src/drizzle-pgis/spatial-type.ts b/src/drizzle-pgis/spatial-type.ts deleted file mode 100644 index d208b65f..00000000 --- a/src/drizzle-pgis/spatial-type.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { PgColumn } from "drizzle-orm/pg-core"; -import { Geometry } from "geojson"; -import { sql } from "drizzle-orm"; - -/** - * https://postgis.net/docs/ST_AsGeoJSON.html - * @returns a geometry or geography as a GeoJSON "geometry" - */ -export const ST_AsGeoJSON = ( - feature: PgColumn<{ - name: string; - tableName: string; - dataType: "custom"; - columnType: "PgCustomColumn"; - data: Geometry; - driverParam: unknown; - notNull: false; - hasDefault: false; - enumValues: undefined; - baseColumn: never; - }>, - maxDecimalDigits = 9, -) => sql`ST_AsGeoJSON(${feature}, ${maxDecimalDigits})`; diff --git a/src/schema/budget-line.ts b/src/schema/budget-line.ts index c494eecc..8d081451 100644 --- a/src/schema/budget-line.ts +++ b/src/schema/budget-line.ts @@ -8,11 +8,7 @@ export const budgetLine = pgTable( code: text("code").references(() => agencyBudget.code), id: text("id"), }, - (table) => { - return { - pk: primaryKey({ columns: [table.code, table.id] }), - }; - }, + (table) => [primaryKey({ columns: [table.code, table.id] })], ); export const budgetLineEntitySchema = z.object({ diff --git a/src/schema/capital-commitment.ts b/src/schema/capital-commitment.ts index 75256196..5e5e66ea 100644 --- a/src/schema/capital-commitment.ts +++ b/src/schema/capital-commitment.ts @@ -25,18 +25,16 @@ export const capitalCommitment = pgTable( budgetLineCode: text("budget_line_code").notNull(), budgetLineId: text("budget_line_id").notNull(), }, - (table) => { - return { - capitalProjectFk: foreignKey({ - columns: [table.managingCode, table.capitalProjectId], - foreignColumns: [capitalProject.managingCode, capitalProject.id], - }), - budgetLineFk: foreignKey({ - columns: [table.budgetLineCode, table.budgetLineId], - foreignColumns: [budgetLine.code, budgetLine.id], - }), - }; - }, + (table) => [ + foreignKey({ + columns: [table.managingCode, table.capitalProjectId], + foreignColumns: [capitalProject.managingCode, capitalProject.id], + }), + foreignKey({ + columns: [table.budgetLineCode, table.budgetLineId], + foreignColumns: [budgetLine.code, budgetLine.id], + }), + ], ); export const capitalCommitmentEntitySchema = z.object({ diff --git a/src/schema/capital-project-checkbook.ts b/src/schema/capital-project-checkbook.ts index be3f348a..192c64f2 100644 --- a/src/schema/capital-project-checkbook.ts +++ b/src/schema/capital-project-checkbook.ts @@ -18,15 +18,13 @@ export const capitalProjectCheckbook = pgTable( capitalProjectId: text("capital_project_id"), value: numeric("value"), }, - (table) => { - return { - fk: foreignKey({ - columns: [table.managingCode, table.capitalProjectId], - foreignColumns: [capitalProject.managingCode, capitalProject.id], - name: "custom_fk", - }), - }; - }, + (table) => [ + foreignKey({ + columns: [table.managingCode, table.capitalProjectId], + foreignColumns: [capitalProject.managingCode, capitalProject.id], + name: "custom_fk", + }), + ], ); export const capitalProjectCategoryEntitySchema = z.object({ diff --git a/src/schema/capital-project-fund.ts b/src/schema/capital-project-fund.ts index 4647dda3..3fea71b6 100644 --- a/src/schema/capital-project-fund.ts +++ b/src/schema/capital-project-fund.ts @@ -37,15 +37,13 @@ export const capitalProjectFund = pgTable( stage: capitalProjectFundStageEnum("stage"), value: numeric("value"), }, - (table) => { - return { - fk: foreignKey({ - columns: [table.managingCode, table.capitalProjectId], - foreignColumns: [capitalProject.managingCode, capitalProject.id], - name: "custom_fk", - }), - }; - }, + (table) => [ + foreignKey({ + columns: [table.managingCode, table.capitalProjectId], + foreignColumns: [capitalProject.managingCode, capitalProject.id], + name: "custom_fk", + }), + ], ); export const capitalProjectFundEntitySchema = z.object({ diff --git a/src/schema/capital-project.ts b/src/schema/capital-project.ts index 85100a5b..8e7ae992 100644 --- a/src/schema/capital-project.ts +++ b/src/schema/capital-project.ts @@ -38,15 +38,13 @@ export const capitalProject = pgTable( mercatorFillMPnt: multiPointGeom("mercator_fill_m_pnt", 3857), mercatorFillMPoly: multiPolygonGeom("mercator_fill_m_poly", 3857), }, - (table) => { - return { - pk: primaryKey({ columns: [table.managingCode, table.id] }), - mercatorFillMPolyGix: index().using("GIST", table.mercatorFillMPoly), - mercatorFillMPntGix: index().using("GIST", table.mercatorFillMPnt), - liFtMPntGix: index().using("GIST", table.liFtMPnt), - liFtMPolyGix: index().using("GIST", table.liFtMPoly), - }; - }, + (table) => [ + primaryKey({ columns: [table.managingCode, table.id] }), + index().using("GIST", table.mercatorFillMPoly), + index().using("GIST", table.mercatorFillMPnt), + index().using("GIST", table.liFtMPnt), + index().using("GIST", table.liFtMPoly), + ], ); export const capitalProjectCategoryEnumSchema = z.enum([ diff --git a/src/schema/city-council-district.ts b/src/schema/city-council-district.ts index 65f55631..a1f0e437 100644 --- a/src/schema/city-council-district.ts +++ b/src/schema/city-council-district.ts @@ -10,13 +10,11 @@ export const cityCouncilDistrict = pgTable( mercatorFill: multiPolygonGeom("mercator_fill", 3857), mercatorLabel: pointGeom("mercator_label", 3857), }, - (table) => { - return { - mercatorFillGix: index().using("GIST", table.mercatorFill), - mercatorLabelGix: index().using("GIST", table.mercatorLabel), - liFtGix: index().using("GIST", table.liFt), - }; - }, + (table) => [ + index().using("GIST", table.mercatorFill), + index().using("GIST", table.mercatorLabel), + index().using("GIST", table.liFt), + ], ); export const cityCouncilDistrictEntitySchema = z.object({ diff --git a/src/schema/community-district.ts b/src/schema/community-district.ts index fe09373d..4b852c68 100644 --- a/src/schema/community-district.ts +++ b/src/schema/community-district.ts @@ -14,14 +14,12 @@ export const communityDistrict = pgTable( mercatorFill: multiPolygonGeom("mercator_fill", 3857), mercatorLabel: pointGeom("mercator_label", 3857), }, - (table) => { - return { - pk: primaryKey({ columns: [table.boroughId, table.id] }), - liFtGix: index().using("GIST", table.liFt), - mercatorFillGix: index().using("GIST", table.mercatorFill), - mercatorLabelGix: index().using("GIST", table.mercatorLabel), - }; - }, + (table) => [ + primaryKey({ columns: [table.boroughId, table.id] }), + index().using("GIST", table.liFt), + index().using("GIST", table.mercatorFill), + index().using("GIST", table.mercatorLabel), + ], ); export const communityDistrictEntitySchema = z.object({