2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
class CreateEmbeddableHosts < ActiveRecord::Migration[4.2]
|
2015-08-18 17:15:46 -04:00
|
|
|
def change
|
|
|
|
create_table :embeddable_hosts, force: true do |t|
|
|
|
|
t.string :host, null: false
|
|
|
|
t.integer :category_id, null: false
|
2017-08-07 11:48:36 -04:00
|
|
|
t.timestamps null: false
|
2015-08-18 17:15:46 -04:00
|
|
|
end
|
|
|
|
|
2018-12-03 22:48:13 -05:00
|
|
|
category_id = 0
|
2015-08-20 16:10:19 -04:00
|
|
|
category_row =
|
|
|
|
execute(
|
|
|
|
"SELECT c.id FROM categories AS c
|
2015-08-18 17:15:46 -04:00
|
|
|
INNER JOIN site_settings AS s ON s.value = c.name
|
2015-08-20 16:10:19 -04:00
|
|
|
WHERE s.name = 'embed_category'",
|
|
|
|
)
|
2015-08-18 17:15:46 -04:00
|
|
|
|
2015-08-20 16:10:19 -04:00
|
|
|
category_id = category_row[0]["id"].to_i if category_row.cmd_tuples > 0
|
2015-08-18 17:15:46 -04:00
|
|
|
|
|
|
|
if category_id == 0
|
|
|
|
category_id =
|
|
|
|
execute("SELECT value FROM site_settings WHERE name = 'uncategorized_category_id'")[0][
|
|
|
|
"value"
|
|
|
|
].to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
embeddable_hosts = execute("SELECT value FROM site_settings WHERE name = 'embeddable_hosts'")
|
|
|
|
if embeddable_hosts && embeddable_hosts.cmd_tuples > 0
|
|
|
|
val = embeddable_hosts[0]["value"]
|
|
|
|
if val.present?
|
|
|
|
records = val.split("\n")
|
|
|
|
if records.present?
|
|
|
|
records.each do |h|
|
|
|
|
execute "INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES ('#{h}', #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
execute "DELETE FROM site_settings WHERE name IN ('embeddable_hosts', 'embed_category')"
|
|
|
|
end
|
|
|
|
end
|