Skip to content

Commit

Permalink
Fix error generating unique index in DB migration (#43)
Browse files Browse the repository at this point in the history
Syntax for creating the index was incorrect
  • Loading branch information
westonganger authored Oct 17, 2023
1 parent 9d520ef commit 10f6859
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CHANGELOG

- **Unreleased**
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.1...master)
* Nothing yet
* [#43](https://github.com/westonganger/active_snapshot/pull/43) - Fix unique index error in generated DB migration

- **v0.3.1** - August 4, 2023
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.0...v0.3.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
def change
create_table :snapshots<%= table_options %> do |t|
t.belongs_to :item, polymorphic: true, null: false, index: true
t.string :identifier, unique: [:item_id, :item_type], index: true
t.belongs_to :user, polymorphic: true

t.string :identifier, index: true
t.index [:identifier, :item_id, :item_type], unique: true

t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :metadata

t.datetime :created_at, null: false
end

create_table :snapshot_items<%= table_options %> do |t|
t.belongs_to :snapshot, null: false, index: true
t.belongs_to :item, polymorphic: true, null: false, unique: [:snapshot_id], index: true

t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :object, null: false

t.datetime :created_at, null: false
t.string :child_group_name
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ class CreateSnapshotsTables < ActiveRecord::Migration::Current
def change
create_table :snapshots do |t|
t.belongs_to :item, polymorphic: true, null: false, index: true
t.string :identifier, unique: true, index: true
t.belongs_to :user, polymorphic: true

if ActiveSnapshot.config.storage_method_native_json?
t.json :metadata
else
t.text :metadata
end
t.string :identifier, index: true
t.index [:identifier, :item_id, :item_type], unique: true

t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :metadata, null: false
t.datetime :created_at, null: false
end
Expand All @@ -19,11 +17,7 @@ def change
t.belongs_to :snapshot, null: false, index: true
t.belongs_to :item, polymorphic: true, null: false, unique: [:snapshot_id], index: true
if ActiveSnapshot.config.storage_method_native_json?
t.json :object, null: false
else
t.text :object, null: false
end
t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :object, null: false

t.datetime :created_at, null: false
t.string :child_group_name
Expand Down

0 comments on commit 10f6859

Please sign in to comment.