Skip to content
Snippets Groups Projects
Unverified Commit 396d29c4 authored by Maxime Orefice's avatar Maxime Orefice
Browse files

Add add_sequence migration helper need to fix spec

parent 3088f933
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -1506,6 +1506,13 @@ def drop_sequence(table_name, column_name, sequence_name)
SQL
end
 
def add_sequence(table_name, column_name, sequence_name, value)
execute <<~SQL
CREATE SEQUENCE #{sequence_name} START #{value};
ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT nextval('#{sequence_name}')
SQL
end
private
 
def create_temporary_columns_and_triggers(table, columns, primary_key: :id, data_type: :bigint)
Loading
Loading
Loading
Loading
@@ -3289,4 +3289,12 @@ def setup
model.drop_sequence(:test_table, :test_column, :test_table_id_seq)
end
end
describe '#add_sequence' do
it "executes the statement to add the sequence" do
expect(model).to receive(:execute).with /CREATE SEQUENCE test_table_id_seq START 1;\nALTER TABLE "test_table" ALTER COLUMN "test_column" SET DEFAULT nextval('test_table_id_seq')/
model.add_sequence(:test_table, :test_column, :test_table_id_seq, 1)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment