forked from AlchemyCMS/alchemy_cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AlchemyCMS#1807 from mamhoff/remove-site-id-from-n…
…odes Remove Site ID from nodes
- Loading branch information
Showing
11 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
class RemoveSiteIdFromNodes < ActiveRecord::Migration[5.2] | ||
def up | ||
remove_foreign_key :alchemy_nodes, :alchemy_sites | ||
remove_index :alchemy_nodes, :site_id | ||
remove_column :alchemy_nodes, :site_id, :integer, null: false | ||
end | ||
|
||
def down | ||
add_column :alchemy_nodes, :site_id, :integer, null: true | ||
sql = <<~SQL | ||
UPDATE alchemy_nodes | ||
SET site_id = ( | ||
SELECT alchemy_languages.site_id FROM alchemy_languages WHERE alchemy_nodes.language_id = alchemy_languages.id | ||
) WHERE | ||
EXISTS ( | ||
SELECT * | ||
FROM alchemy_languages | ||
WHERE alchemy_languages.id = alchemy_nodes.language_id | ||
); | ||
SQL | ||
|
||
connection.execute(sql) | ||
change_column :alchemy_nodes, :site_id, :integer, null: false | ||
add_index :alchemy_nodes, :site_id | ||
add_foreign_key :alchemy_nodes, :alchemy_sites, column: :site_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
spec/dummy/db/migrate/20200504210159_remove_site_id_from_nodes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../db/migrate/20200504210159_remove_site_id_from_nodes.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters