OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/db/migrate/20190724093332_add_journal_...

29 lines
765 B

require_relative './migration_utils/utils'
class AddJournalVersionsTable < ActiveRecord::Migration[5.2]
include ::Migration::Utils
def up
create_table :journal_versions do |t|
t.string :journable_type
t.integer :journable_id
t.integer :version, default: 0
t.index %i[journable_type journable_id version],
name: 'unique_journal_version',
unique: true
end
ActiveRecord::Base.connection.execute <<-SQL
INSERT INTO journal_versions (journable_type, journable_id, version)
(SELECT
journable_type, journable_id, MAX(version)
FROM journals
GROUP BY journable_type, journable_id);
SQL
end
def down
drop_table :journal_versions
end
end