tags: add tag_versions table.
Add a tag_versions table for tracking the history of tags. A couple notable differences from other version tables: * There is a previous_version_id column that points to the previous version. This allows finding the first, last, previous, or next version efficiently in SQL. * There is a `version` column that tracks the revision number (1, 2, 3, etc). Post versions and note versions have this, but other version tables don't. * The `updater_id` column is optional. This is because we don't know who the last updater was before we started tracking the history of tags, so the initial updater will be NULL in the first version of the tag.
This commit is contained in:
23
db/migrate/20220909211649_create_tag_versions.rb
Normal file
23
db/migrate/20220909211649_create_tag_versions.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class CreateTagVersions < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :tag_versions do |t|
|
||||
t.timestamps
|
||||
t.references :tag, null: false, foreign_key: { to_table: :tags }
|
||||
t.references :updater, null: true, foreign_key: { to_table: :users }
|
||||
t.references :previous_version, null: true, foreign_key: { to_table: :tag_versions }
|
||||
|
||||
t.column :version, :integer, null: false
|
||||
t.column :name, :string, null: false
|
||||
t.column :category, :integer, null: false
|
||||
t.column :is_deprecated, :boolean, null: false
|
||||
|
||||
t.index :name, opclass: :text_pattern_ops
|
||||
t.index :name, name: "index_tag_versions_on_name_trgm", using: :gin, opclass: :gin_trgm_ops
|
||||
t.index :version
|
||||
t.index :category
|
||||
t.index :is_deprecated
|
||||
|
||||
t.index [:tag_id, :previous_version_id], unique: true
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user