add account_id to submissions
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddAccountIdToSubmissions < ActiveRecord::Migration[7.1]
|
||||
class MigrationSubmission < ApplicationRecord
|
||||
self.table_name = 'submissions'
|
||||
end
|
||||
|
||||
class MigrationTemplate < ApplicationRecord
|
||||
self.table_name = 'templates'
|
||||
end
|
||||
|
||||
class MigrationAccount < ApplicationRecord
|
||||
self.table_name = 'accounts'
|
||||
end
|
||||
|
||||
def change
|
||||
add_reference :submissions, :account, index: true, null: true
|
||||
|
||||
MigrationAccount.all.each do |account|
|
||||
MigrationSubmission.where(template_id: MigrationTemplate.where(account_id: account.id).select(:id))
|
||||
.update_all(account_id: account.id)
|
||||
end
|
||||
|
||||
change_column_null :submissions, :account_id, false
|
||||
end
|
||||
end
|
||||
+3
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_01_210319) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_03_113454) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@@ -151,6 +151,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_01_210319) do
|
||||
t.string "submitters_order", null: false
|
||||
t.string "slug", null: false
|
||||
t.text "preferences", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.index ["account_id"], name: "index_submissions_on_account_id"
|
||||
t.index ["created_by_user_id"], name: "index_submissions_on_created_by_user_id"
|
||||
t.index ["slug"], name: "index_submissions_on_slug", unique: true
|
||||
t.index ["template_id"], name: "index_submissions_on_template_id"
|
||||
|
||||
Reference in New Issue
Block a user