From 6b1a1834ad1715145f047790c8391b8a5558bece Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 20 Dec 2023 20:34:25 +0000 Subject: Created new Operation model and fixed Event associations with it --- db/migrate/20231220194440_create_operations.rb | 9 +++++++++ .../20231220195147_remove_organisation_from_events.rb | 5 +++++ db/migrate/20231220195530_add_operation_to_events.rb | 5 +++++ .../20231220202718_add_organisation_ref_to_operations.rb | 5 +++++ db/schema.rb | 15 ++++++++++++--- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20231220194440_create_operations.rb create mode 100644 db/migrate/20231220195147_remove_organisation_from_events.rb create mode 100644 db/migrate/20231220195530_add_operation_to_events.rb create mode 100644 db/migrate/20231220202718_add_organisation_ref_to_operations.rb (limited to 'db') diff --git a/db/migrate/20231220194440_create_operations.rb b/db/migrate/20231220194440_create_operations.rb new file mode 100644 index 0000000..85a2ee3 --- /dev/null +++ b/db/migrate/20231220194440_create_operations.rb @@ -0,0 +1,9 @@ +class CreateOperations < ActiveRecord::Migration[7.1] + def change + create_table :operations do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20231220195147_remove_organisation_from_events.rb b/db/migrate/20231220195147_remove_organisation_from_events.rb new file mode 100644 index 0000000..5198e98 --- /dev/null +++ b/db/migrate/20231220195147_remove_organisation_from_events.rb @@ -0,0 +1,5 @@ +class RemoveOrganisationFromEvents < ActiveRecord::Migration[7.1] + def change + remove_reference :events, :organisation, null: false, foreign_key: true + end +end diff --git a/db/migrate/20231220195530_add_operation_to_events.rb b/db/migrate/20231220195530_add_operation_to_events.rb new file mode 100644 index 0000000..b95ded0 --- /dev/null +++ b/db/migrate/20231220195530_add_operation_to_events.rb @@ -0,0 +1,5 @@ +class AddOperationToEvents < ActiveRecord::Migration[7.1] + def change + add_reference :events, :operation, null: false, foreign_key: true + end +end diff --git a/db/migrate/20231220202718_add_organisation_ref_to_operations.rb b/db/migrate/20231220202718_add_organisation_ref_to_operations.rb new file mode 100644 index 0000000..939c6e5 --- /dev/null +++ b/db/migrate/20231220202718_add_organisation_ref_to_operations.rb @@ -0,0 +1,5 @@ +class AddOrganisationRefToOperations < ActiveRecord::Migration[7.1] + def change + add_reference :operations, :organisation, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 07579bb..4ad3bbd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,14 +10,22 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_12_18_190546) do +ActiveRecord::Schema[7.1].define(version: 2023_12_20_202718) do create_table "events", force: :cascade do |t| t.date "date" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "operation_id", null: false + t.index ["operation_id"], name: "index_events_on_operation_id" + end + + create_table "operations", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "organisation_id", null: false - t.index ["organisation_id"], name: "index_events_on_organisation_id" + t.index ["organisation_id"], name: "index_operations_on_organisation_id" end create_table "organisations", force: :cascade do |t| @@ -26,5 +34,6 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_18_190546) do t.datetime "updated_at", null: false end - add_foreign_key "events", "organisations" + add_foreign_key "events", "operations" + add_foreign_key "operations", "organisations" end -- cgit v1.2.3