Skip to content

Commit 1a7e8fe

Browse files
committed
Update migrations to utilize different data structure
1 parent 7a2f9f3 commit 1a7e8fe

6 files changed

+53
-58
lines changed

db/migrate/20201230233349_create_partner_group_memberships.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

db/migrate/20210116200129_create_partner_group_items.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AddUniqunessIdxOnNameAndOrganizationIdInPartnerGroups < ActiveRecord::Migration[6.1]
2+
disable_ddl_transaction!
3+
4+
def change
5+
add_index :partner_groups, [:name, :organization_id], unique: true, algorithm: :concurrently
6+
end
7+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AddReferenceBetweenPartnersAndPartnerGroups < ActiveRecord::Migration[6.1]
2+
disable_ddl_transaction!
3+
4+
def change
5+
add_reference :partners, :partner_groups, index: { algorithm: :concurrently }
6+
end
7+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class AddJoinTableBetweenPartnerGroupsToItemCategories < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :partner_groups_item_categories do |t|
4+
t.references :partner, foreign_key: true
5+
t.references :item_categories, foreign_key: true
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20_210_107_175_100) do
14-
13+
ActiveRecord::Schema.define(version: 20_210_729_003_516) do
1514
# These are extensions that must be enabled in order to support this database
1615
enable_extension "plpgsql"
1716

@@ -33,7 +32,7 @@
3332
t.bigint "record_id", null: false
3433
t.datetime "created_at", null: false
3534
t.datetime "updated_at", null: false
36-
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
35+
t.index %w(record_type record_id name), name: "index_action_text_rich_texts_uniqueness", unique: true
3736
end
3837

3938
create_table "active_storage_attachments", force: :cascade do |t|
@@ -43,7 +42,7 @@
4342
t.bigint "blob_id", null: false
4443
t.datetime "created_at", null: false
4544
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
46-
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
45+
t.index %w(record_type record_id name blob_id), name: "index_active_storage_attachments_uniqueness", unique: true
4746
end
4847

4948
create_table "active_storage_blobs", force: :cascade do |t|
@@ -63,7 +62,7 @@
6362
t.string "variation_digest", null: false
6463
t.datetime "created_at", precision: 6, null: false
6564
t.datetime "updated_at", precision: 6, null: false
66-
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
65+
t.index %w(blob_id variation_digest), name: "index_active_storage_variant_records_uniqueness", unique: true
6766
end
6867

6968
create_table "adjustments", id: :serial, force: :cascade do |t|
@@ -100,7 +99,7 @@
10099
t.datetime "updated_at", null: false
101100
t.integer "organization_id"
102101
t.string "barcodeable_type", default: "Item"
103-
t.index ["barcodeable_type", "barcodeable_id"], name: "index_barcode_items_on_barcodeable_type_and_barcodeable_id"
102+
t.index %w(barcodeable_type barcodeable_id), name: "index_barcode_items_on_barcodeable_type_and_barcodeable_id"
104103
t.index ["organization_id"], name: "index_barcode_items_on_organization_id"
105104
end
106105

@@ -137,7 +136,7 @@
137136
t.string "business_name"
138137
t.float "latitude"
139138
t.float "longitude"
140-
t.index ["latitude", "longitude"], name: "index_diaper_drive_participants_on_latitude_and_longitude"
139+
t.index %w(latitude longitude), name: "index_diaper_drive_participants_on_latitude_and_longitude"
141140
end
142141

143142
create_table "diaper_drives", force: :cascade do |t|
@@ -176,7 +175,7 @@
176175
t.integer "organization_id"
177176
t.float "latitude"
178177
t.float "longitude"
179-
t.index ["latitude", "longitude"], name: "index_donation_sites_on_latitude_and_longitude"
178+
t.index %w(latitude longitude), name: "index_donation_sites_on_latitude_and_longitude"
180179
t.index ["organization_id"], name: "index_donation_sites_on_organization_id"
181180
end
182181

@@ -213,7 +212,7 @@
213212
t.string "value"
214213
t.datetime "created_at", null: false
215214
t.datetime "updated_at", null: false
216-
t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true
215+
t.index %w(feature_key key value), name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true
217216
end
218217

219218
create_table "inventory_items", id: :serial, force: :cascade do |t|
@@ -225,12 +224,12 @@
225224
end
226225

227226
create_table "item_categories", force: :cascade do |t|
228-
t.string "name"
227+
t.string "name", null: false
229228
t.text "description"
230229
t.integer "organization_id", null: false
231230
t.datetime "created_at", precision: 6, null: false
232231
t.datetime "updated_at", precision: 6, null: false
233-
t.index ["name", "organization_id"], name: "index_item_categories_on_name_and_organization_id", unique: true
232+
t.index %w(name organization_id), name: "index_item_categories_on_name_and_organization_id", unique: true
234233
end
235234

236235
create_table "items", id: :serial, force: :cascade do |t|
@@ -264,7 +263,7 @@
264263
t.boolean "active", default: true
265264
t.boolean "visible_to_partners", default: true, null: false
266265
t.integer "value_in_cents", default: 0
267-
t.index ["name", "organization_id"], name: "index_kits_on_name_and_organization_id", unique: true
266+
t.index %w(name organization_id), name: "index_kits_on_name_and_organization_id", unique: true
268267
t.index ["organization_id"], name: "index_kits_on_organization_id"
269268
end
270269

@@ -275,7 +274,7 @@
275274
t.string "itemizable_type"
276275
t.datetime "created_at", null: false
277276
t.datetime "updated_at", null: false
278-
t.index ["itemizable_id", "itemizable_type"], name: "index_line_items_on_itemizable_id_and_itemizable_type"
277+
t.index %w(itemizable_id itemizable_type), name: "index_line_items_on_itemizable_id_and_itemizable_type"
279278
end
280279

281280
create_table "manufacturers", force: :cascade do |t|
@@ -306,34 +305,26 @@
306305
t.integer "default_storage_location"
307306
t.text "partner_form_fields", default: [], array: true
308307
t.integer "account_request_id"
309-
t.index ["latitude", "longitude"], name: "index_organizations_on_latitude_and_longitude"
308+
t.index %w(latitude longitude), name: "index_organizations_on_latitude_and_longitude"
310309
t.index ["short_name"], name: "index_organizations_on_short_name"
311310
end
312311

313-
create_table "partner_group_items", force: :cascade do |t|
314-
t.bigint "partner_group_id", null: false
315-
t.bigint "item_id", null: false
312+
create_table "partner_groups", force: :cascade do |t|
313+
t.bigint "organization_id"
314+
t.string "name"
316315
t.datetime "created_at", precision: 6, null: false
317316
t.datetime "updated_at", precision: 6, null: false
318-
t.index ["item_id"], name: "index_partner_group_items_on_item_id"
319-
t.index ["partner_group_id"], name: "index_partner_group_items_on_partner_group_id"
317+
t.index %w(name organization_id), name: "index_partner_groups_on_name_and_organization_id", unique: true
318+
t.index ["organization_id"], name: "index_partner_groups_on_organization_id"
320319
end
321320

322-
create_table "partner_group_memberships", force: :cascade do |t|
323-
t.bigint "partner_group_id"
321+
create_table "partner_groups_item_categories", force: :cascade do |t|
324322
t.bigint "partner_id"
323+
t.bigint "item_categories_id"
325324
t.datetime "created_at", precision: 6, null: false
326325
t.datetime "updated_at", precision: 6, null: false
327-
t.index ["partner_group_id"], name: "index_partner_group_memberships_on_partner_group_id"
328-
t.index ["partner_id"], name: "index_partner_group_memberships_on_partner_id"
329-
end
330-
331-
create_table "partner_groups", force: :cascade do |t|
332-
t.bigint "organization_id"
333-
t.string "name"
334-
t.datetime "created_at", precision: 6, null: false
335-
t.datetime "updated_at", precision: 6, null: false
336-
t.index ["organization_id"], name: "index_partner_groups_on_organization_id"
326+
t.index ["item_categories_id"], name: "index_partner_groups_item_categories_on_item_categories_id"
327+
t.index ["partner_id"], name: "index_partner_groups_item_categories_on_partner_id"
337328
end
338329

339330
create_table "partners", id: :serial, force: :cascade do |t|
@@ -346,7 +337,9 @@
346337
t.boolean "send_reminders", default: false, null: false
347338
t.text "notes"
348339
t.integer "quota"
340+
t.bigint "partner_groups_id"
349341
t.index ["organization_id"], name: "index_partners_on_organization_id"
342+
t.index ["partner_groups_id"], name: "index_partners_on_partner_groups_id"
350343
end
351344

352345
create_table "purchases", force: :cascade do |t|
@@ -391,7 +384,7 @@
391384
t.float "longitude"
392385
t.integer "square_footage"
393386
t.string "warehouse_type"
394-
t.index ["latitude", "longitude"], name: "index_storage_locations_on_latitude_and_longitude"
387+
t.index %w(latitude longitude), name: "index_storage_locations_on_latitude_and_longitude"
395388
t.index ["organization_id"], name: "index_storage_locations_on_organization_id"
396389
end
397390

@@ -437,7 +430,7 @@
437430
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
438431
t.index ["invitations_count"], name: "index_users_on_invitations_count"
439432
t.index ["invited_by_id"], name: "index_users_on_invited_by_id"
440-
t.index ["invited_by_type", "invited_by_id"], name: "index_users_on_invited_by_type_and_invited_by_id"
433+
t.index %w(invited_by_type invited_by_id), name: "index_users_on_invited_by"
441434
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
442435
end
443436

@@ -453,7 +446,7 @@
453446
t.float "longitude"
454447
t.datetime "created_at", null: false
455448
t.datetime "updated_at", null: false
456-
t.index ["latitude", "longitude"], name: "index_vendors_on_latitude_and_longitude"
449+
t.index %w(latitude longitude), name: "index_vendors_on_latitude_and_longitude"
457450
end
458451

459452
create_table "versions", force: :cascade do |t|
@@ -483,11 +476,9 @@
483476
add_foreign_key "kits", "organizations"
484477
add_foreign_key "manufacturers", "organizations"
485478
add_foreign_key "organizations", "account_requests"
486-
add_foreign_key "partner_group_items", "items"
487-
add_foreign_key "partner_group_items", "partner_groups"
488-
add_foreign_key "partner_group_memberships", "partner_groups"
489-
add_foreign_key "partner_group_memberships", "partners"
490479
add_foreign_key "partner_groups", "organizations"
480+
add_foreign_key "partner_groups_item_categories", "item_categories", column: "item_categories_id"
481+
add_foreign_key "partner_groups_item_categories", "partners"
491482
add_foreign_key "requests", "distributions"
492483
add_foreign_key "requests", "organizations"
493484
add_foreign_key "requests", "partners"

0 commit comments

Comments
 (0)