Skip to content

Commit

Permalink
Remove Site ID from nodes
Browse files Browse the repository at this point in the history
Nodes can get their Site through their language.
  • Loading branch information
mamhoff committed May 4, 2020
1 parent 489181e commit 662616f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/models/alchemy/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Node < BaseRecord
acts_as_nested_set scope: 'language_id', touch: true
stampable stamper_class_name: Alchemy.user_class_name

belongs_to :site, class_name: 'Alchemy::Site'
belongs_to :language, class_name: 'Alchemy::Language'
belongs_to :page, class_name: 'Alchemy::Page', optional: true, inverse_of: :nodes

Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20200504210159_remove_site_id_from_nodes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class RemoveSiteIdFromNodes < ActiveRecord::Migration[6.0]
def up
remove_index :alchemy_nodes, :site_id
remove_column :alchemy_nodes, :site_id, :integer, null: false
end

def down
# This IS, in fact, reversible - but it's cumbersome to do. If someone tells me it benefits them
# I will implement.
raise ActiveRecord::IrreversibleMigration
end
end
12 changes: 12 additions & 0 deletions spec/dummy/db/migrate/20200504210159_remove_site_id_from_nodes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class RemoveSiteIdFromNodes < ActiveRecord::Migration[6.0]
def up
remove_index :alchemy_nodes, :site_id
remove_column :alchemy_nodes, :site_id, :integer, null: false
end

def down
# This IS, in fact, reversible - but it's cumbersome to do. If someone tells me it benefits them
# I will implement.
raise ActiveRecord::IrreversibleMigration
end
end
5 changes: 1 addition & 4 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_02_26_213334) do
ActiveRecord::Schema.define(version: 2020_05_04_210159) do

create_table "alchemy_attachments", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -221,14 +221,12 @@
t.integer "updater_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "site_id", null: false
t.index ["creator_id"], name: "index_alchemy_nodes_on_creator_id"
t.index ["language_id"], name: "index_alchemy_nodes_on_language_id"
t.index ["lft"], name: "index_alchemy_nodes_on_lft"
t.index ["page_id"], name: "index_alchemy_nodes_on_page_id"
t.index ["parent_id"], name: "index_alchemy_nodes_on_parent_id"
t.index ["rgt"], name: "index_alchemy_nodes_on_rgt"
t.index ["site_id"], name: "index_alchemy_nodes_on_site_id"
t.index ["updater_id"], name: "index_alchemy_nodes_on_updater_id"
end

Expand Down Expand Up @@ -363,5 +361,4 @@
add_foreign_key "alchemy_essence_pages", "alchemy_pages", column: "page_id"
add_foreign_key "alchemy_nodes", "alchemy_languages", column: "language_id"
add_foreign_key "alchemy_nodes", "alchemy_pages", column: "page_id", on_delete: :cascade
add_foreign_key "alchemy_nodes", "alchemy_sites", column: "site_id", on_delete: :cascade
end

0 comments on commit 662616f

Please sign in to comment.