From 63d85933ac99453c76df7cda102a4f60d94f5f53 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 10 Nov 2017 13:00:36 +0100 Subject: Migrate all foreign keys to `bigint` from `integer` All our primary keys are supposed to be `bigint`s, and our foreign keys should likewise be `bigint`s. But it's easy to forget this when creating migrations, or some committers might not have been up to speed on the convention. In any case, this changes all existing foreign keys to be `bigint`s. Need to get this out now so that Michel Etienne can use it to correctly test the Java application for compliance check validations. That's why I'm not including any future-looking checks or enforcements here. That will be coming next. Refs #4947 --- ...171110114408_change_foreign_keys_to_bigint_2.rb | 20 +++++++ db/schema.rb | 62 +++++++++++----------- 2 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 db/migrate/20171110114408_change_foreign_keys_to_bigint_2.rb diff --git a/db/migrate/20171110114408_change_foreign_keys_to_bigint_2.rb b/db/migrate/20171110114408_change_foreign_keys_to_bigint_2.rb new file mode 100644 index 000000000..3bd4525ff --- /dev/null +++ b/db/migrate/20171110114408_change_foreign_keys_to_bigint_2.rb @@ -0,0 +1,20 @@ +class ChangeForeignKeysToBigint2 < ActiveRecord::Migration + def change + change_column :api_keys, :organisation_id, :bigint + change_column :compliance_check_blocks, :compliance_check_set_id, :bigint + change_column :compliance_check_messages, :compliance_check_id, :bigint + change_column :compliance_check_messages, :compliance_check_resource_id, :bigint + change_column :compliance_check_messages, :compliance_check_set_id, :bigint + change_column :compliance_check_sets, :referential_id, :bigint + change_column :compliance_check_sets, :compliance_control_set_id, :bigint + change_column :compliance_check_sets, :workbench_id, :bigint + change_column :compliance_check_sets, :parent_id, :bigint + change_column :compliance_checks, :compliance_check_set_id, :bigint + change_column :compliance_checks, :compliance_check_block_id, :bigint + change_column :compliance_control_blocks, :compliance_control_set_id, :bigint + change_column :compliance_control_sets, :organisation_id, :bigint + change_column :compliance_controls, :compliance_control_set_id, :bigint + change_column :compliance_controls, :compliance_control_block_id, :bigint + change_column :time_tables, :created_from_id, :bigint + end +end diff --git a/db/schema.rb b/db/schema.rb index d6823e8b0..1af5ea187 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171109101514) do +ActiveRecord::Schema.define(version: 20171110114408) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -77,7 +77,7 @@ ActiveRecord::Schema.define(version: 20171109101514) do t.string "name" t.datetime "created_at" t.datetime "updated_at" - t.integer "organisation_id" + t.integer "organisation_id", limit: 8 end add_index "api_keys", ["organisation_id"], name: "index_api_keys_on_organisation_id", using: :btree @@ -148,23 +148,23 @@ ActiveRecord::Schema.define(version: 20171109101514) do create_table "compliance_check_blocks", id: :bigserial, force: :cascade do |t| t.string "name" t.hstore "condition_attributes" - t.integer "compliance_check_set_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "compliance_check_set_id", limit: 8 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "compliance_check_blocks", ["compliance_check_set_id"], name: "index_compliance_check_blocks_on_compliance_check_set_id", using: :btree create_table "compliance_check_messages", id: :bigserial, force: :cascade do |t| - t.integer "compliance_check_id" - t.integer "compliance_check_resource_id" + t.integer "compliance_check_id", limit: 8 + t.integer "compliance_check_resource_id", limit: 8 t.string "message_key" t.hstore "message_attributes" t.hstore "resource_attributes" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "status" - t.integer "compliance_check_set_id" + t.integer "compliance_check_set_id", limit: 8 end add_index "compliance_check_messages", ["compliance_check_id"], name: "index_compliance_check_messages_on_compliance_check_id", using: :btree @@ -185,15 +185,15 @@ ActiveRecord::Schema.define(version: 20171109101514) do add_index "compliance_check_resources", ["compliance_check_set_id"], name: "index_compliance_check_resources_on_compliance_check_set_id", using: :btree create_table "compliance_check_sets", id: :bigserial, force: :cascade do |t| - t.integer "referential_id" - t.integer "compliance_control_set_id" - t.integer "workbench_id" + t.integer "referential_id", limit: 8 + t.integer "compliance_control_set_id", limit: 8 + t.integer "workbench_id", limit: 8 t.string "creator" t.string "status" - t.integer "parent_id" + t.integer "parent_id", limit: 8 t.string "parent_type" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "current_step_id" t.float "current_step_progress" t.string "name" @@ -207,16 +207,16 @@ ActiveRecord::Schema.define(version: 20171109101514) do add_index "compliance_check_sets", ["workbench_id"], name: "index_compliance_check_sets_on_workbench_id", using: :btree create_table "compliance_checks", id: :bigserial, force: :cascade do |t| - t.integer "compliance_check_set_id" - t.integer "compliance_check_block_id" + t.integer "compliance_check_set_id", limit: 8 + t.integer "compliance_check_block_id", limit: 8 t.string "type" t.hstore "control_attributes" t.string "name" t.string "code" t.string "criticity" t.text "comment" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "origin_code" end @@ -226,34 +226,34 @@ ActiveRecord::Schema.define(version: 20171109101514) do create_table "compliance_control_blocks", id: :bigserial, force: :cascade do |t| t.string "name" t.hstore "condition_attributes" - t.integer "compliance_control_set_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "compliance_control_set_id", limit: 8 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "compliance_control_blocks", ["compliance_control_set_id"], name: "index_compliance_control_blocks_on_compliance_control_set_id", using: :btree create_table "compliance_control_sets", id: :bigserial, force: :cascade do |t| t.string "name" - t.integer "organisation_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "organisation_id", limit: 8 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "compliance_control_sets", ["organisation_id"], name: "index_compliance_control_sets_on_organisation_id", using: :btree create_table "compliance_controls", id: :bigserial, force: :cascade do |t| - t.integer "compliance_control_set_id" + t.integer "compliance_control_set_id", limit: 8 t.string "type" t.hstore "control_attributes" t.string "name" t.string "code" t.string "criticity" t.text "comment" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "origin_code" - t.integer "compliance_control_block_id" + t.integer "compliance_control_block_id", limit: 8 end add_index "compliance_controls", ["code", "compliance_control_set_id"], name: "index_compliance_controls_on_code_and_compliance_control_set_id", unique: true, using: :btree @@ -835,7 +835,7 @@ ActiveRecord::Schema.define(version: 20171109101514) do t.datetime "created_at" t.datetime "updated_at" t.string "color" - t.integer "created_from_id" + t.integer "created_from_id", limit: 8 t.string "checksum" t.text "checksum_source" t.string "data_source_ref" -- cgit v1.2.3 From 5538c5dc2c81d98bd9f069d4fd859cd79b8b0756 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 10 Nov 2017 14:08:12 +0100 Subject: Change `compliance_check_set_id` to `bigint` I had missed this one in 63d85933ac99453c76df7cda102a4f60d94f5f53. Thanks a lot to Robert for scouring the fields and finding it. Since the v2 migration was irreversible, add a new one to change the type of this foreign key. Refs #4947 --- db/migrate/20171110130416_change_foreign_keys_to_bigint_3.rb | 5 +++++ db/schema.rb | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20171110130416_change_foreign_keys_to_bigint_3.rb diff --git a/db/migrate/20171110130416_change_foreign_keys_to_bigint_3.rb b/db/migrate/20171110130416_change_foreign_keys_to_bigint_3.rb new file mode 100644 index 000000000..bfe1b4be2 --- /dev/null +++ b/db/migrate/20171110130416_change_foreign_keys_to_bigint_3.rb @@ -0,0 +1,5 @@ +class ChangeForeignKeysToBigint3 < ActiveRecord::Migration + def change + change_column :compliance_check_resources, :compliance_check_set_id, :bigint + end +end diff --git a/db/schema.rb b/db/schema.rb index 1af5ea187..cab058eb7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171110114408) do +ActiveRecord::Schema.define(version: 20171110130416) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -177,9 +177,9 @@ ActiveRecord::Schema.define(version: 20171110114408) do t.string "type" t.string "reference" t.hstore "metrics" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "compliance_check_set_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "compliance_check_set_id", limit: 8 end add_index "compliance_check_resources", ["compliance_check_set_id"], name: "index_compliance_check_resources_on_compliance_check_set_id", using: :btree -- cgit v1.2.3