Skip to content

Commit

Permalink
Ensure that the old_housing and old_event tables are restored during …
Browse files Browse the repository at this point in the history
…the down() migration
  • Loading branch information
loicguillois authored and Falinor committed Sep 19, 2024
1 parent 926bc24 commit 216907b
Showing 1 changed file with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
import type { Knex } from "knex";

import type { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists('old_housing');
await knex.schema.dropTableIfExists('old_events');
await knex.schema.dropTableIfExists('housing');
}


export async function down(knex: Knex): Promise<void> {
await Promise.all([
knex.schema.createTable('old_housing', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
table.string('invariant').notNullable();
table.string('local_id').notNullable();
table.string('building_id').notNullable();
table.specificType('raw_address', 'text[]').notNullable();
table.string('geo_code').notNullable();
table.double('latitude').notNullable();
table.double('longitude').notNullable();
table.integer('cadastral_classification').notNullable();
table.boolean('uncomfortable').notNullable();
table.integer('vacancy_start_year').notNullable();
table.string('housing_kind').notNullable();
table.integer('rooms_count').notNullable();
table.integer('living_area').notNullable();
table.string('cadastral_reference').notNullable();
table.integer('building_year');
table.date('mutation_date').notNullable();
table.boolean('taxed').notNullable();
table.specificType('vacancy_reasons', 'text[]');
table.specificType('data_years', 'integer[]').defaultTo('{2021}');
table.integer('beneficiary_count');
table.string('building_location');
table.integer('rental_value');
table.string('ownership_kind');
table.integer('status');
table.string('sub_status');
table.string('precisions');
table.string('energy_consumption');
table.string('energy_consumption_worst');
table.string('occupancy').notNullable().defaultTo('V');
table.unique(['local_id'], { indexName: 'housing_local_id_idx' });
table.index(
['geo_code', 'data_years'],
'housing_geo_code_data_years_idx'
);
table.index(['geo_code'], 'housing_geo_code_idx');
}),
knex.schema.createTable('housing', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
table.string('invariant').notNullable();
Expand All @@ -31,11 +67,6 @@ export async function down(knex: Knex): Promise<void> {
table.boolean('taxed').notNullable();
table.specificType('vacancy_reasons', 'text[]');
table.specificType('data_years', 'integer[]').defaultTo('{2021}');
table.string('building_id').nullable().alter();
table.boolean('taxed').nullable().alter();
table.date('mutation_date').nullable().alter();
table.double('latitude').nullable().alter();
table.double('longitude').nullable().alter();
table.integer('beneficiary_count');
table.string('building_location');
table.integer('rental_value');
Expand All @@ -49,16 +80,24 @@ export async function down(knex: Knex): Promise<void> {
table.string('occupancy_registered').notNullable().defaultTo('V');
table.string('occupancy_intended');
table.string('occupancy').notNullable().defaultTo('V');
table.string('invariant').nullable().alter();
table.integer('vacancy_start_year').nullable().alter();
table.string('cadastral_reference').nullable().alter();
table.string('plot_id');
table.unique(['local_id'], { indexName: 'housing_local_id_idx' });
table.index(
['geo_code', 'data_years'],
'housing_geo_code_data_years_idx',
'housing_geo_code_data_years_idx'
);
table.index(['geo_code'], 'housing_geo_code_idx');
}),
knex.schema.createTable('old_events', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
table.uuid('campaign_id').references('id').inTable('campaigns');
table.uuid('housing_id').references('id').inTable('housing').alter();
table.uuid('owner_id').references('id').inTable('owners').alter();
table.string('kind').notNullable();
table.timestamp('created_at').defaultTo(knex.fn.now());
table.string('content');
table.text('contact_kind');
table.string('title').defaultTo(null);
})
]);
}

0 comments on commit 216907b

Please sign in to comment.