Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions db/migrate/20240226201050_add_precision_to_timestamps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

class AddPrecisionToTimestamps < ActiveRecord::Migration[7.1]
SKIP_TABLES = [:schema_migrations, :ar_internal_metadata].freeze

def up
migrate_precision(precision: 6)
end

def down
migrate_precision(precision: nil)
end

def migrate_precision(precision:)
table_names = ActiveRecord::Base.connection.tables.map(&:to_sym)
table_names.each do |table|
next if SKIP_TABLES.include?(table)

ActiveRecord::Base.connection.columns(table).each do |column|
next unless datetime_column?(column)

change_column(table, column.name, :datetime, precision:)
end
end
end

private

def datetime_column?(column)
column.sql_type_metadata.type == :datetime
end
end
22 changes: 11 additions & 11 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.