Skip to content

Commit 6799b51

Browse files
committed
Added primary key type to generated migration - resolves #57
1 parent 9972bd9 commit 6799b51

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/generators/authtrail/install_generator.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ def mysql?
7878
def adapter
7979
ActiveRecord::Base.connection_db_config.adapter.to_s
8080
end
81+
82+
def primary_key_type
83+
", id: :#{key_type}" if key_type
84+
end
85+
86+
def foreign_key_type
87+
", type: :#{key_type}" if key_type
88+
end
89+
90+
def key_type
91+
Rails.configuration.generators.options.dig(:active_record, :primary_key_type)
92+
end
8193
end
8294
end
8395
end

lib/generators/authtrail/templates/login_activities_migration.rb.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
22
def change
3-
create_table :login_activities do |t|
3+
create_table :login_activities<%= primary_key_type %> do |t|
44
t.string :scope
55
t.string :strategy
66
<%= identity_column %>
77
t.boolean :success
88
t.string :failure_reason
9-
t.references :user, polymorphic: true
9+
t.references :user<%= foreign_key_type %>, polymorphic: true
1010
t.string :context
1111
<%= ip_column %>
1212
t.text :user_agent

test/install_generator_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ def test_encryption_none
2828
assert_file "app/models/login_activity.rb", /LoginActivity < ApplicationRecord/
2929
assert_migration "db/migrate/create_login_activities.rb", /t.string :identity, index: true/
3030
end
31+
32+
def test_primary_key_type
33+
Rails.configuration.generators.stub(:options, {active_record: {primary_key_type: :uuid}}) do
34+
run_generator ["--encryption=lockbox"]
35+
end
36+
assert_migration "db/migrate/create_login_activities.rb", /id: :uuid/
37+
assert_migration "db/migrate/create_login_activities.rb", /type: :uuid/
38+
end
3139
end

0 commit comments

Comments
 (0)