Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise if updated_by exists already #42

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/temporal_tables/temporal_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def create_table(table_name, **options, &block) # rubocop:disable Metrics/Method
super(table_name, **valid_options) do |t|
block.call t

if TemporalTables.add_updated_by_field && !skip_table
if TemporalTables.add_updated_by_field &&
(options[:temporal] || TemporalTables.create_by_default && !skip_table)
updated_by_already_exists = t.columns.any? { |c| c.name == 'updated_by' }
if updated_by_already_exists
puts "consider adding #{table_name} to TemporalTables skip_table" # rubocop:disable Rails/Output
else
t.column(:updated_by, TemporalTables.updated_by_type)
end
raise "#{table_name} updated_by column exists already" if updated_by_already_exists

t.column(:updated_by, TemporalTables.updated_by_type)

end
end

Expand Down Expand Up @@ -54,10 +54,13 @@ def add_temporal_table(table_name, **options) # rubocop:disable Metrics/MethodLe
end
end

if TemporalTables.add_updated_by_field && !column_exists?(table_name, :updated_by)
if TemporalTables.add_updated_by_field
raise "#{table_name} updated_by column exists already" if column_exists?(table_name, :updated_by)

change_table table_name do |t|
t.column :updated_by, TemporalTables.updated_by_type
end

end

original_primary_key = original_primary_key(table_name)
Expand Down