Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added bigint for ID columns #481

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/generators/audited/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InstallGenerator < Rails::Generators::Base
extend Audited::Generators::Migration

class_option :audited_changes_column_type, type: :string, default: "text", required: false
class_option :audited_user_id_column_type, type: :string, default: "integer", required: false
class_option :audited_user_id_column_type, type: :string, default: "bigint", required: false

source_root File.expand_path("../templates", __FILE__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
add_column :audits, :association_id, :integer
add_column :audits, :association_id, :bigint
add_column :audits, :association_type, :string
end

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/audited/templates/install.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class <%= migration_class_name %> < <%= migration_parent %>
def self.up
create_table :audits, :force => true do |t|
t.column :auditable_id, :integer
t.column :auditable_id, :bigint
t.column :auditable_type, :string
t.column :associated_id, :integer
t.column :associated_id, :bigint
t.column :associated_type, :string
t.column :user_id, :<%= options[:audited_user_id_column_type] %>
t.column :user_type, :string
Expand Down
28 changes: 28 additions & 0 deletions test/install_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,32 @@ class InstallGeneratorTest < Rails::Generators::TestCase
assert_includes(content, "class InstallAudited < #{parent}\n")
end
end

test "generate migration with 'bigint' type for user_id column" do
run_generator %w(--audited-user-id-column-type bigint)

assert_migration "db/migrate/install_audited.rb" do |content|
assert_includes(content, 'class InstallAudited')
assert_includes(content, 't.column :user_id, :bigint')
end
end

test "generate migration with 'bigint' type for auditable_id column" do
run_generator

assert_migration "db/migrate/install_audited.rb" do |content|
assert_includes(content, 'class InstallAudited')
assert_includes(content, 't.column :auditable_id, :bigint')
end
end

test "generate migration with 'bigint' type for associated_id column" do
run_generator

assert_migration "db/migrate/install_audited.rb" do |content|
assert_includes(content, 'class InstallAudited')
assert_includes(content, 't.column :associated_id, :bigint')
end
end

end
2 changes: 1 addition & 1 deletion test/upgrade_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
run_generator %w(upgrade)

assert_migration "db/migrate/add_association_to_audits.rb" do |content|
assert_match(/add_column :audits, :association_id, :integer/, content)
assert_match(/add_column :audits, :association_id, :bigint/, content)
assert_match(/add_column :audits, :association_type, :string/, content)
end
end
Expand Down