Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions database/migrations/20240202100000 - all:id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.removeColumn('incidents', 'id'),
queryInterface.removeColumn('markers', 'id'),
queryInterface.removeColumn('properties', 'id'),
queryInterface.removeColumn('timelines', 'id'),
queryInterface.removeColumn('transactions', 'id'),
]);
},

down: (queryInterface, Sequelize) => {
const signature = {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
};

Promise.all([
queryInterface.addColumn('incidents', 'id', signature),
queryInterface.addColumn('markers', 'id', signature),
queryInterface.addColumn('properties', 'id', signature),
queryInterface.addColumn('timelines', 'id', signature),
queryInterface.addColumn('transactions', 'id', signature),
]);
}
};
7 changes: 1 addition & 6 deletions src/models/incident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DataTypes } from 'sequelize';
import { coordinateFields } from './utils';

export type IncidentType = {
id: number,
date: string,
lat: number,
lng: number,
Expand All @@ -15,11 +14,6 @@ export default (sequelize: Sequelize) => {
const model = sequelize.define(
'Incident',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
date: DataTypes.DATEONLY,
...coordinateFields(),
type: DataTypes.STRING,
Expand All @@ -30,6 +24,7 @@ export default (sequelize: Sequelize) => {
timestamps: false,
}
);
model.removeAttribute('id');

return model;
};
7 changes: 1 addition & 6 deletions src/models/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DataTypes } from 'sequelize';
import { coordinateFields } from './utils';

export type MarkerType = {
id: number,
lat: number,
lng: number,
type: string,
Expand All @@ -19,11 +18,6 @@ export default (sequelize: Sequelize) => {
const model = sequelize.define(
'Marker',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
...coordinateFields(),
type: DataTypes.STRING,
label: DataTypes.STRING,
Expand All @@ -33,6 +27,7 @@ export default (sequelize: Sequelize) => {
timestamps: false,
}
);
model.removeAttribute('id');

return model;
};
11 changes: 3 additions & 8 deletions src/models/property.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import type { Sequelize } from 'sequelize';
import { DataTypes } from 'sequelize';

import type { GloballyIdentifiedModel, IdentifiedModel } from "../orm.types";

export type PropertyType = {
guid: string
postcode: string,
propertyType: string,
propertyForm: string,
paon: string,
saon: string,
street: string,
city: string,
} & GloballyIdentifiedModel & IdentifiedModel;
};

export default (sequelize: Sequelize) => {
const model = sequelize.define(
'Property',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
guid: {
type: DataTypes.STRING,
unique: true,
Expand Down Expand Up @@ -49,6 +43,7 @@ export default (sequelize: Sequelize) => {
timestamps: false,
}
);
model.removeAttribute('id');

return model;
};
10 changes: 2 additions & 8 deletions src/models/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import type { Sequelize } from 'sequelize';
import { DataTypes } from 'sequelize';

import type { IdentifiedModel } from "../orm.types";

export type TimelineType = {
postcode: string,
date: string,
avg: number,
count: number,
} & IdentifiedModel;
};

export default (sequelize: Sequelize) => {
const model = sequelize.define(
'Timeline',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
postcode: {
type: DataTypes.STRING(9),
primaryKey: true,
Expand All @@ -35,6 +28,7 @@ export default (sequelize: Sequelize) => {
timestamps: false,
}
);
model.removeAttribute('id');

//@ts-ignore
model.associate = ({ Postcode, Timeline }) => {
Expand Down
18 changes: 7 additions & 11 deletions src/models/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import type { Sequelize } from 'sequelize';
import { DataTypes } from 'sequelize';
import type { GloballyIdentifiedModel, IdentifiedModel } from "../orm.types";

export type TransactionType = {
price: number,
date: string,
} & GloballyIdentifiedModel & IdentifiedModel;

// https://www.gov.uk/guidance/about-the-price-paid-data#download-options
// [
Expand Down Expand Up @@ -40,15 +34,16 @@ export type TransactionType = {
// Note that where a transaction changes category type due to misallocation (as above) it will be deleted from the original category type and added to the correct category with a new transaction unique identifier.
// ]

export type TransactionType = {
guid: string
price: number,
date: string,
};

export default (sequelize: Sequelize) => {
const model = sequelize.define(
'Transaction',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
guid: DataTypes.STRING,
price: DataTypes.INTEGER,
date: DataTypes.DATEONLY,
Expand All @@ -58,6 +53,7 @@ export default (sequelize: Sequelize) => {
timestamps: false,
}
);
model.removeAttribute('id');

//@ts-ignore
model.associate = ({ Property, Transaction }) => {
Expand Down
8 changes: 0 additions & 8 deletions src/orm.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ export type ORM = {
Incident: ModelStatic<Model<IncidentType>>,
Marker: ModelStatic<Model<MarkerType>>,
};

export type IdentifiedModel = {
id: number
}

export type GloballyIdentifiedModel = {
guid: string
}