add homie to the gang when homie is created
This commit is contained in:
5
db/migrate/20201007182916_add_name_to_gangs.rb
Normal file
5
db/migrate/20201007182916_add_name_to_gangs.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddNameToGangs < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :gangs, :name, :text
|
||||
end
|
||||
end
|
||||
5
db/migrate/20201007183139_add_gang_relation_to_homies.rb
Normal file
5
db/migrate/20201007183139_add_gang_relation_to_homies.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddGangRelationToHomies < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_reference :homies, :gang
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
class AddInitialGangAndConnectToHomies < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
# execute "INSERT INTO gangs SELECT 'name' WHERE NOT EXISTS (SELECT * FROM gangs)"
|
||||
if Gang.count.zero?
|
||||
Gang.create.save
|
||||
end
|
||||
gang = Gang.first
|
||||
|
||||
Homie.all.update(gang: gang)
|
||||
end
|
||||
|
||||
def down
|
||||
Homie.all.update(gang: nil)
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_10_07_180902) do
|
||||
ActiveRecord::Schema.define(version: 2020_10_07_213411) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -43,6 +43,7 @@ ActiveRecord::Schema.define(version: 2020_10_07_180902) do
|
||||
t.integer "chip_scale"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "name"
|
||||
end
|
||||
|
||||
create_table "homies", force: :cascade do |t|
|
||||
@@ -51,6 +52,8 @@ ActiveRecord::Schema.define(version: 2020_10_07_180902) do
|
||||
t.text "about"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "gang_id"
|
||||
t.index ["gang_id"], name: "index_homies_on_gang_id"
|
||||
end
|
||||
|
||||
create_table "money_moves", force: :cascade do |t|
|
||||
|
||||
Reference in New Issue
Block a user