From e91c7177809ebca0cc95d18305a00b8b1079df82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 6 Dec 2024 10:39:48 +0000 Subject: [PATCH] feat: Setup Prisma migrations (#146) * chore: Bump prisma * feat: Setup initial migration * feat: GHA workflow --- .github/workflows/deploy-migrations.yaml | 23 ++++++ package-lock.json | 56 +++++++------- package.json | 2 +- prisma/migrations/0_init/migration.sql | 98 ++++++++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + 5 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/deploy-migrations.yaml create mode 100644 prisma/migrations/0_init/migration.sql create mode 100644 prisma/migrations/migration_lock.toml diff --git a/.github/workflows/deploy-migrations.yaml b/.github/workflows/deploy-migrations.yaml new file mode 100644 index 00000000..818ebe77 --- /dev/null +++ b/.github/workflows/deploy-migrations.yaml @@ -0,0 +1,23 @@ +name: Deploy migrations +on: + push: + paths: + # Only run this workflow when migrations are updated + - prisma/migrations/** + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Setup Node + uses: actions/setup-node@v3 + - name: Install dependencies + run: npm install + - name: Apply all pending migrations to the database + run: npx prisma migrate deploy + env: + DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5964d51e..5024ef05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ "lint-staged": "^15.2.10", "postcss": "^8", "prettier": "3.3.3", - "prisma": "^5.21.1", + "prisma": "^5.22.0", "tailwindcss": "^3.4.14", "ts-jest": "^29.2.5", "tsuml2": "^0.17.0", @@ -1579,48 +1579,48 @@ } }, "node_modules/@prisma/debug": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz", - "integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.22.0.tgz", + "integrity": "sha512-AUt44v3YJeggO2ZU5BkXI7M4hu9BF2zzH2iF2V5pyXT/lRTyWiElZ7It+bRH1EshoMRxHgpYg4VB6rCM+mG5jQ==", "devOptional": true }, "node_modules/@prisma/engines": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz", - "integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.22.0.tgz", + "integrity": "sha512-UNjfslWhAt06kVL3CjkuYpHAWSO6L4kDCVPegV6itt7nD1kSJavd3vhgAEhjglLJJKEdJ7oIqDJ+yHk6qO8gPA==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/debug": "5.21.1", - "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "@prisma/fetch-engine": "5.21.1", - "@prisma/get-platform": "5.21.1" + "@prisma/debug": "5.22.0", + "@prisma/engines-version": "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2", + "@prisma/fetch-engine": "5.22.0", + "@prisma/get-platform": "5.22.0" } }, "node_modules/@prisma/engines-version": { - "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", - "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", + "version": "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2.tgz", + "integrity": "sha512-2PTmxFR2yHW/eB3uqWtcgRcgAbG1rwG9ZriSvQw+nnb7c4uCr3RAcGMb6/zfE88SKlC1Nj2ziUvc96Z379mHgQ==", "devOptional": true }, "node_modules/@prisma/fetch-engine": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz", - "integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.22.0.tgz", + "integrity": "sha512-bkrD/Mc2fSvkQBV5EpoFcZ87AvOgDxbG99488a5cexp5Ccny+UM6MAe/UFkUC0wLYD9+9befNOqGiIJhhq+HbA==", "devOptional": true, "dependencies": { - "@prisma/debug": "5.21.1", - "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "@prisma/get-platform": "5.21.1" + "@prisma/debug": "5.22.0", + "@prisma/engines-version": "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2", + "@prisma/get-platform": "5.22.0" } }, "node_modules/@prisma/get-platform": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz", - "integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.22.0.tgz", + "integrity": "sha512-pHhpQdr1UPFpt+zFfnPazhulaZYCUqeIcPpJViYoq9R+D/yw4fjE+CtnsnKzPYm0ddUbeXUzjGVGIRVgPDCk4Q==", "devOptional": true, "dependencies": { - "@prisma/debug": "5.21.1" + "@prisma/debug": "5.22.0" } }, "node_modules/@radix-ui/primitive": { @@ -8929,13 +8929,13 @@ "peer": true }, "node_modules/prisma": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz", - "integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.22.0.tgz", + "integrity": "sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/engines": "5.21.1" + "@prisma/engines": "5.22.0" }, "bin": { "prisma": "build/index.js" diff --git a/package.json b/package.json index 08b85ce4..cb18dab3 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "lint-staged": "^15.2.10", "postcss": "^8", "prettier": "3.3.3", - "prisma": "^5.21.1", + "prisma": "^5.22.0", "tailwindcss": "^3.4.14", "ts-jest": "^29.2.5", "tsuml2": "^0.17.0", diff --git a/prisma/migrations/0_init/migration.sql b/prisma/migrations/0_init/migration.sql new file mode 100644 index 00000000..e0c5474b --- /dev/null +++ b/prisma/migrations/0_init/migration.sql @@ -0,0 +1,98 @@ +-- CreateTable +CREATE TABLE "buildprices" ( + "id" SERIAL NOT NULL, + "housetypedescription" VARCHAR(250), + "housetype" VARCHAR(1), + "pricerange" VARCHAR(50), + "pricemid" DOUBLE PRECISION, + + CONSTRAINT "buildprices_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "gdhi" ( + "id" SERIAL NOT NULL, + "itllevel" VARCHAR(250), + "itl3" VARCHAR(250), + "region" VARCHAR(250), + "gdhi_2020" DOUBLE PRECISION, + + CONSTRAINT "gdhi_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "hpi" ( + "id" SERIAL NOT NULL, + "region" VARCHAR(250), + "itl3" VARCHAR(250), + "ladcode" VARCHAR(250), + "hpi_2000" DOUBLE PRECISION, + + CONSTRAINT "hpi_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "itl_lookup" ( + "postcode" TEXT, + "district" TEXT, + "areacode" TEXT, + "itl3" TEXT, + "id" SERIAL NOT NULL, + + CONSTRAINT "itl_lookup_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "pricespaid" ( + "id" SERIAL NOT NULL, + "transactionidentifier" VARCHAR(250), + "price" DOUBLE PRECISION, + "postcode" VARCHAR(250), + "propertytype" VARCHAR(250), + "newbuild" VARCHAR(250), + + CONSTRAINT "pricespaid_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "rent" ( + "id" SERIAL NOT NULL, + "itl3" VARCHAR(250), + "ladcode" VARCHAR(250), + "region" VARCHAR(250), + "monthlymeanrent" DOUBLE PRECISION, + + CONSTRAINT "rent_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "soc_rent_adjustments" ( + "year" VARCHAR(10), + "inflation" DOUBLE PRECISION, + "additional" DOUBLE PRECISION, + "total" DOUBLE PRECISION, + "id" SERIAL NOT NULL, + + CONSTRAINT "soc_rent_adjustments_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "socialrent" ( + "id" SERIAL NOT NULL, + "county" VARCHAR(250), + "itl3" VARCHAR(250), + "earningsperweek" DOUBLE PRECISION, + + CONSTRAINT "socialrent_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "gas_bills" ( + "id" INTEGER NOT NULL, + "Region" VARCHAR NOT NULL, + "itl" VARCHAR NOT NULL, + "bill" DOUBLE PRECISION NOT NULL, + + CONSTRAINT "gas_bills_pkey" PRIMARY KEY ("id") +); + diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..fbffa92c --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file