Add NOT NULL requirement to account columns on AccountPin (#33244)
				
					
				
			This commit is contained in:
		
							parent
							
								
									e76aff7de5
								
							
						
					
					
						commit
						e4e35ab134
					
				| @ -5,10 +5,10 @@ | |||||||
| # Table name: account_pins | # Table name: account_pins | ||||||
| # | # | ||||||
| #  id                :bigint(8)        not null, primary key | #  id                :bigint(8)        not null, primary key | ||||||
| #  account_id        :bigint(8) |  | ||||||
| #  target_account_id :bigint(8) |  | ||||||
| #  created_at        :datetime         not null | #  created_at        :datetime         not null | ||||||
| #  updated_at        :datetime         not null | #  updated_at        :datetime         not null | ||||||
|  | #  account_id        :bigint(8)        not null | ||||||
|  | #  target_account_id :bigint(8)        not null | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| class AccountPin < ApplicationRecord | class AccountPin < ApplicationRecord | ||||||
|  | |||||||
| @ -0,0 +1,23 @@ | |||||||
|  | # frozen_string_literal: true | ||||||
|  | 
 | ||||||
|  | class AddNotNullToAccountPinAccountColumns < ActiveRecord::Migration[7.2] | ||||||
|  |   def up | ||||||
|  |     connection.execute(<<~SQL.squish) | ||||||
|  |       DELETE FROM account_pins | ||||||
|  |       WHERE account_id IS NULL | ||||||
|  |       OR target_account_id IS NULL | ||||||
|  |     SQL | ||||||
|  | 
 | ||||||
|  |     safety_assured do | ||||||
|  |       change_column_null :account_pins, :account_id, false | ||||||
|  |       change_column_null :account_pins, :target_account_id, false | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   def down | ||||||
|  |     safety_assured do | ||||||
|  |       change_column_null :account_pins, :account_id, true | ||||||
|  |       change_column_null :account_pins, :target_account_id, true | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
| @ -10,7 +10,7 @@ | |||||||
| # | # | ||||||
| # It's strongly recommended that you check this file into your version control system. | # It's strongly recommended that you check this file into your version control system. | ||||||
| 
 | 
 | ||||||
| ActiveRecord::Schema[7.2].define(version: 2024_12_05_163118) do | ActiveRecord::Schema[7.2].define(version: 2024_12_10_140838) do | ||||||
|   # These are extensions that must be enabled in order to support this database |   # These are extensions that must be enabled in order to support this database | ||||||
|   enable_extension "plpgsql" |   enable_extension "plpgsql" | ||||||
| 
 | 
 | ||||||
| @ -82,8 +82,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_05_163118) do | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   create_table "account_pins", force: :cascade do |t| |   create_table "account_pins", force: :cascade do |t| | ||||||
|     t.bigint "account_id" |     t.bigint "account_id", null: false | ||||||
|     t.bigint "target_account_id" |     t.bigint "target_account_id", null: false | ||||||
|     t.datetime "created_at", precision: nil, null: false |     t.datetime "created_at", precision: nil, null: false | ||||||
|     t.datetime "updated_at", precision: nil, null: false |     t.datetime "updated_at", precision: nil, null: false | ||||||
|     t.index ["account_id", "target_account_id"], name: "index_account_pins_on_account_id_and_target_account_id", unique: true |     t.index ["account_id", "target_account_id"], name: "index_account_pins_on_account_id_and_target_account_id", unique: true | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user