converting serial types to bigserial

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-01 15:59:26 +01:00
parent e9181c904b
commit 41571c33b4
5 changed files with 867 additions and 9 deletions

View file

@ -0,0 +1,22 @@
BEGIN; -- Start a transaction
-- Update the data type for the "property" table
ALTER TABLE "property" ALTER COLUMN "id" SET DATA TYPE bigint;
ALTER SEQUENCE "property_id_seq" AS bigint; -- Replace with actual sequence name
-- Update the data type for the "property_details_epc" table
ALTER TABLE "property_details_epc" ALTER COLUMN "id" SET DATA TYPE bigint;
ALTER SEQUENCE "property_details_epc_id_seq" AS bigint; -- Replace with actual sequence name
-- Update the data type for the "property_details_meter" table
ALTER TABLE "property_details_meter" ALTER COLUMN "id" SET DATA TYPE bigint;
ALTER SEQUENCE "property_details_meter_id_seq" AS bigint; -- Replace with actual sequence name
-- Update the data type for the "property_targets" table
ALTER TABLE "property_targets" ALTER COLUMN "id" SET DATA TYPE bigint;
ALTER SEQUENCE "property_targets_id_seq" AS bigint; -- Replace with actual sequence name
COMMIT; -- Commit the transaction
ALTER TABLE "property_targets" ALTER COLUMN "property_id" SET DATA TYPE bigint;--> statement-breakpoint
ALTER TABLE "property_targets" ALTER COLUMN "portfolio_id" SET DATA TYPE bigint;

View file

@ -0,0 +1,830 @@
{
"version": "5",
"dialect": "pg",
"id": "2a18a773-c7ce-4a1e-90f5-e189b9865f00",
"prevId": "2501e06e-b010-4eab-8b98-fea030e533e3",
"tables": {
"portfolio": {
"name": "portfolio",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"budget": {
"name": "budget",
"type": "real",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "status",
"primaryKey": false,
"notNull": true
},
"goal": {
"name": "goal",
"type": "goal",
"primaryKey": false,
"notNull": true
},
"cost": {
"name": "cost",
"type": "real",
"primaryKey": false,
"notNull": false
},
"number_of_properties": {
"name": "number_of_properties",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"co2_equivalent_savings": {
"name": "co2_equivalent_savings",
"type": "real",
"primaryKey": false,
"notNull": false
},
"energy_savings": {
"name": "energy_savings",
"type": "real",
"primaryKey": false,
"notNull": false
},
"energy_cost_savings": {
"name": "energy_cost_savings",
"type": "real",
"primaryKey": false,
"notNull": false
},
"property_valuation_increase": {
"name": "property_valuation_increase",
"type": "real",
"primaryKey": false,
"notNull": false
},
"rental_yield_increase": {
"name": "rental_yield_increase",
"type": "real",
"primaryKey": false,
"notNull": false
},
"total_work_hours": {
"name": "total_work_hours",
"type": "real",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp (6) with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (6) with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
},
"portfolioUsers": {
"name": "portfolioUsers",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"portfolio_id": {
"name": "portfolio_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"role": {
"name": "role",
"type": "role",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp (6) with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (6) with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"portfolioUsers_user_id_user_id_fk": {
"name": "portfolioUsers_user_id_user_id_fk",
"tableFrom": "portfolioUsers",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"portfolioUsers_portfolio_id_portfolio_id_fk": {
"name": "portfolioUsers_portfolio_id_portfolio_id_fk",
"tableFrom": "portfolioUsers",
"tableTo": "portfolio",
"columnsFrom": [
"portfolio_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {}
},
"property": {
"name": "property",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "bigserial",
"primaryKey": true,
"notNull": true
},
"portfolio_id": {
"name": "portfolio_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"creation_status": {
"name": "creation_status",
"type": "creation_status",
"primaryKey": false,
"notNull": true
},
"uprn": {
"name": "uprn",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"building_reference_number": {
"name": "building_reference_number",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "status",
"primaryKey": false,
"notNull": false
},
"address": {
"name": "address",
"type": "text",
"primaryKey": false,
"notNull": false
},
"postcode": {
"name": "postcode",
"type": "text",
"primaryKey": false,
"notNull": false
},
"has_pre_condition_report": {
"name": "has_pre_condition_report",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"has_recommendations": {
"name": "has_recommendations",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"property_type": {
"name": "property_type",
"type": "text",
"primaryKey": false,
"notNull": false
},
"built_form": {
"name": "built_form",
"type": "text",
"primaryKey": false,
"notNull": false
},
"local_authority": {
"name": "local_authority",
"type": "text",
"primaryKey": false,
"notNull": false
},
"constituency": {
"name": "constituency",
"type": "text",
"primaryKey": false,
"notNull": false
},
"number_of_rooms": {
"name": "number_of_rooms",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"year_built": {
"name": "year_built",
"type": "text",
"primaryKey": false,
"notNull": false
},
"tenure": {
"name": "tenure",
"type": "text",
"primaryKey": false,
"notNull": false
},
"current_epc_rating": {
"name": "current_epc_rating",
"type": "epc",
"primaryKey": false,
"notNull": false
},
"current_sap_points": {
"name": "current_sap_points",
"type": "real",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"property_portfolio_id_portfolio_id_fk": {
"name": "property_portfolio_id_portfolio_id_fk",
"tableFrom": "property",
"tableTo": "portfolio",
"columnsFrom": [
"portfolio_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {}
},
"property_details_epc": {
"name": "property_details_epc",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "bigserial",
"primaryKey": true,
"notNull": true
},
"property_id": {
"name": "property_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"portfolio_id": {
"name": "portfolio_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"full_address": {
"name": "full_address",
"type": "text",
"primaryKey": false,
"notNull": false
},
"total_floor_area": {
"name": "total_floor_area",
"type": "real",
"primaryKey": false,
"notNull": false
},
"walls": {
"name": "walls",
"type": "text",
"primaryKey": false,
"notNull": false
},
"walls_rating": {
"name": "walls_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"roof": {
"name": "roof",
"type": "text",
"primaryKey": false,
"notNull": false
},
"roof_rating": {
"name": "roof_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"floor": {
"name": "floor",
"type": "text",
"primaryKey": false,
"notNull": false
},
"floor_rating": {
"name": "floor_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"windows": {
"name": "windows",
"type": "text",
"primaryKey": false,
"notNull": false
},
"windows_rating": {
"name": "windows_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"heating": {
"name": "heating",
"type": "text",
"primaryKey": false,
"notNull": false
},
"heating_rating": {
"name": "heating_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"heating_contols": {
"name": "heating_contols",
"type": "text",
"primaryKey": false,
"notNull": false
},
"heating_contols_rating": {
"name": "heating_contols_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"hot_water": {
"name": "hot_water",
"type": "text",
"primaryKey": false,
"notNull": false
},
"hot_water_rating": {
"name": "hot_water_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"lighting": {
"name": "lighting",
"type": "text",
"primaryKey": false,
"notNull": false
},
"lighting_rating": {
"name": "lighting_rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"mainfuel": {
"name": "mainfuel",
"type": "text",
"primaryKey": false,
"notNull": false
},
"ventilation": {
"name": "ventilation",
"type": "text",
"primaryKey": false,
"notNull": false
},
"solar_pv": {
"name": "solar_pv",
"type": "real",
"primaryKey": false,
"notNull": false
},
"solar_hot_water": {
"name": "solar_hot_water",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"wind_turbine": {
"name": "wind_turbine",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"floor_height": {
"name": "floor_height",
"type": "real",
"primaryKey": false,
"notNull": false
},
"number_heated_rooms": {
"name": "number_heated_rooms",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"heat_loss_corridor": {
"name": "heat_loss_corridor",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"unheated_corridor_length": {
"name": "unheated_corridor_length",
"type": "real",
"primaryKey": false,
"notNull": false
},
"number_of_open_fireplaces": {
"name": "number_of_open_fireplaces",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"number_of_extensions": {
"name": "number_of_extensions",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"number_of_storeys": {
"name": "number_of_storeys",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"mains_gas": {
"name": "mains_gas",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"energy_tariff": {
"name": "energy_tariff",
"type": "text",
"primaryKey": false,
"notNull": false
},
"primary_energy_consumption": {
"name": "primary_energy_consumption",
"type": "real",
"primaryKey": false,
"notNull": false
},
"co2_emissions": {
"name": "co2_emissions",
"type": "real",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"property_details_epc_property_id_property_id_fk": {
"name": "property_details_epc_property_id_property_id_fk",
"tableFrom": "property_details_epc",
"tableTo": "property",
"columnsFrom": [
"property_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"property_details_epc_portfolio_id_portfolio_id_fk": {
"name": "property_details_epc_portfolio_id_portfolio_id_fk",
"tableFrom": "property_details_epc",
"tableTo": "portfolio",
"columnsFrom": [
"portfolio_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {}
},
"property_details_meter": {
"name": "property_details_meter",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "bigserial",
"primaryKey": true,
"notNull": true
},
"uprn": {
"name": "uprn",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"energy_supplier": {
"name": "energy_supplier",
"type": "text",
"primaryKey": false,
"notNull": false
},
"gas_supplier": {
"name": "gas_supplier",
"type": "text",
"primaryKey": false,
"notNull": false
},
"meter_reading_total": {
"name": "meter_reading_total",
"type": "real",
"primaryKey": false,
"notNull": false
},
"meter_reading_electricity": {
"name": "meter_reading_electricity",
"type": "real",
"primaryKey": false,
"notNull": false
},
"meter_reading_gas": {
"name": "meter_reading_gas",
"type": "real",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
},
"property_targets": {
"name": "property_targets",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "bigserial",
"primaryKey": true,
"notNull": true
},
"property_id": {
"name": "property_id",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"portfolio_id": {
"name": "portfolio_id",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"epc": {
"name": "epc",
"type": "epc",
"primaryKey": false,
"notNull": false
},
"heat_demand": {
"name": "heat_demand",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"property_targets_property_id_property_id_fk": {
"name": "property_targets_property_id_property_id_fk",
"tableFrom": "property_targets",
"tableTo": "property",
"columnsFrom": [
"property_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"property_targets_portfolio_id_portfolio_id_fk": {
"name": "property_targets_portfolio_id_portfolio_id_fk",
"tableFrom": "property_targets",
"tableTo": "portfolio",
"columnsFrom": [
"portfolio_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {}
},
"user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"firstName": {
"name": "firstName",
"type": "text",
"primaryKey": false,
"notNull": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"oauth_id": {
"name": "oauth_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"oauth_provider": {
"name": "oauth_provider",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp (6) with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp (6) with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
}
},
"enums": {
"goal": {
"name": "goal",
"values": {
"Valuation Improvement": "Valuation Improvement",
"Increasing EPC": "Increasing EPC",
"Reducing CO2 emissions": "Reducing CO2 emissions",
"Energy Savings": "Energy Savings",
"None": "None"
}
},
"role": {
"name": "role",
"values": {
"creator": "creator",
"admin": "admin",
"read": "read",
"write": "write"
}
},
"status": {
"name": "status",
"values": {
"scoping": "scoping",
"assessment": "assessment",
"tendering": "tendering",
"project underway": "project underway",
"completion; status: on track": "completion; status: on track",
"completion; status: delayed": "completion; status: delayed",
"completion; status: at risk": "completion; status: at risk",
"completion; status: completed": "completion; status: completed",
"needs review": "needs review"
}
},
"epc": {
"name": "epc",
"values": {
"A": "A",
"B": "B",
"C": "C",
"D": "D",
"E": "E",
"F": "F",
"G": "G"
}
},
"creation_status": {
"name": "creation_status",
"values": {
"LOADING": "LOADING",
"READY": "READY",
"ERROR": "ERROR"
}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View file

@ -141,6 +141,13 @@
"when": 1690901194560,
"tag": "0019_certain_pepper_potts",
"breakpoints": true
},
{
"idx": 20,
"version": "5",
"when": 1690901400408,
"tag": "0020_busy_quentin_quire",
"breakpoints": true
}
]
}

View file

@ -1,5 +1,4 @@
import {
serial,
bigserial,
text,
timestamp,
@ -79,7 +78,7 @@ export const epcEnum = pgEnum("epc", Epc);
export const propertyStatusEnum = pgEnum("status", PortfolioStatus);
export const property = pgTable("property", {
id: serial("id").primaryKey(),
id: bigserial("id", { mode: "bigint" }).primaryKey(),
portfolioId: integer("portfolio_id")
.notNull()
.references(() => portfolio.id),
@ -117,7 +116,7 @@ export const FeatureRating: [string, ...string[]] = [
export const FeatureRatingNumeric: [number, ...number[]] = [5, 4, 3, 2, 1];
export const propertyDetailsEpc = pgTable("property_details_epc", {
id: serial("id").primaryKey(),
id: bigserial("id", { mode: "bigint" }).primaryKey(),
propertyId: integer("property_id")
.notNull()
.references(() => property.id),
@ -161,7 +160,7 @@ export const propertyDetailsEpc = pgTable("property_details_epc", {
});
export const propertyDetailsMeter = pgTable("property_details_meter", {
id: serial("id").primaryKey(),
id: bigserial("id", { mode: "bigint" }).primaryKey(),
uprn: bigint("uprn", { mode: "bigint" }),
energySupplier: text("energy_supplier"),
gasSupplier: text("gas_supplier"),
@ -171,11 +170,11 @@ export const propertyDetailsMeter = pgTable("property_details_meter", {
});
export const propertyTargets = pgTable("property_targets", {
id: serial("id").primaryKey(),
propertyId: integer("property_id")
id: bigserial("id", { mode: "bigint" }).primaryKey(),
propertyId: bigint("property_id", { mode: "bigint" })
.notNull()
.references(() => property.id),
portfolioId: integer("portfolio_id")
portfolioId: bigint("portfolio_id", { mode: "bigint" })
.notNull()
.references(() => portfolio.id),
createdAt: timestamp("created_at").notNull().defaultNow(),

View file

@ -1,8 +1,8 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
// "target": "es5",
"target": "ESNext",
"target": "es5",
// "target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,