Skip to content

Commit

Permalink
Respect configured primary key type in pay migration
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmidt authored Aug 9, 2023
1 parent 16786d4 commit f2b3470
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions db/migrate/1_create_pay_tables.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This migration comes from pay (originally 1)
class CreatePayTables < ActiveRecord::Migration[6.0]
def change
create_table :pay_customers do |t|
t.belongs_to :owner, polymorphic: true, index: false
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :pay_customers, id: :uuid do |t|
t.belongs_to :owner, polymorphic: true, index: false, type: foreign_key_type
t.string :processor, null: false
t.string :processor_id
t.boolean :default
Expand All @@ -12,8 +15,8 @@ def change
add_index :pay_customers, [:owner_type, :owner_id, :deleted_at, :default], name: :pay_customer_owner_index
add_index :pay_customers, [:processor, :processor_id], unique: true

create_table :pay_merchants do |t|
t.belongs_to :owner, polymorphic: true, index: false
create_table :pay_merchants, id: :uuid do |t|
t.belongs_to :owner, polymorphic: true, index: false, type: foreign_key_type
t.string :processor, null: false
t.string :processor_id
t.boolean :default
Expand All @@ -22,8 +25,8 @@ def change
end
add_index :pay_merchants, [:owner_type, :owner_id, :processor]

create_table :pay_payment_methods do |t|
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false
create_table :pay_payment_methods, id: :uuid do |t|
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type
t.string :processor_id, null: false
t.boolean :default
t.string :type
Expand All @@ -32,8 +35,8 @@ def change
end
add_index :pay_payment_methods, [:customer_id, :processor_id], unique: true

create_table :pay_subscriptions do |t|
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false
create_table :pay_subscriptions, id: :uuid do |t|
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type
t.string :name, null: false
t.string :processor_id, null: false
t.string :processor_plan, null: false
Expand All @@ -56,9 +59,9 @@ def change
add_index :pay_subscriptions, [:metered]
add_index :pay_subscriptions, [:pause_starts_at]

create_table :pay_charges do |t|
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false
t.belongs_to :subscription, foreign_key: {to_table: :pay_subscriptions}, null: true
create_table :pay_charges, id: :uuid do |t|
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type
t.belongs_to :subscription, foreign_key: {to_table: :pay_subscriptions}, null: true, type: foreign_key_type
t.string :processor_id, null: false
t.integer :amount, null: false
t.string :currency
Expand All @@ -70,11 +73,20 @@ def change
end
add_index :pay_charges, [:customer_id, :processor_id], unique: true

create_table :pay_webhooks do |t|
create_table :pay_webhooks, id: :uuid do |t|
t.string :processor
t.string :event_type
t.public_send Pay::Adapter.json_column_type, :event
t.timestamps
end
end

private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end

0 comments on commit f2b3470

Please sign in to comment.