Skip to content

Commit

Permalink
Add strong_migrations gem and annotate existing migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
nudded committed Aug 22, 2024
1 parent 681bdfa commit 626427f
Show file tree
Hide file tree
Showing 183 changed files with 1,427 additions and 1,073 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ gem 'pg'
gem 'ransack', '~> 4.1.0'
gem 'scenic'
gem 'with_advisory_lock'
gem 'strong_migrations'

# Currencies, Countries, Timezones...
gem 'bigdecimal'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ GEM
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
stripe (6.5.0)
strong_migrations (2.0.0)
activerecord (>= 6.1)
strscan (3.1.0)
temple (0.8.2)
terminal-table (3.0.2)
Expand Down Expand Up @@ -947,6 +949,7 @@ DEPENDENCIES
slim-rails
standard
stripe
strong_migrations
timecop
tzinfo-data
uglifier
Expand Down
477 changes: 239 additions & 238 deletions db/migrate/20220525122759_init_schema.rb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion db/migrate/20220601150058_add_add_on_to_fees.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class AddAddOnToFees < ActiveRecord::Migration[7.0]
def change
add_reference :fees, :applied_add_on, type: :uuid, foreign_key: true, index: true
safety_assured do
add_reference :fees, :applied_add_on, type: :uuid, foreign_key: true, index: true
end
end
end
26 changes: 14 additions & 12 deletions db/migrate/20220620141910_add_invoice_fields_to_organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

class AddInvoiceFieldsToOrganizations < ActiveRecord::Migration[7.0]
def change
change_table :organizations, bulk: true do |t|
t.string :country
t.string :address_line1
t.string :address_line2
t.string :state
t.string :zipcode
t.string :email
t.string :city
t.string :logo
t.string :legal_name
t.string :legal_number
t.text :invoice_footer
safety_assured do
change_table :organizations, bulk: true do |t|
t.string :country
t.string :address_line1
t.string :address_line2
t.string :state
t.string :zipcode
t.string :email
t.string :city
t.string :logo
t.string :legal_name
t.string :legal_number
t.text :invoice_footer
end
end
end
end
8 changes: 5 additions & 3 deletions db/migrate/20220620150551_add_slug_to_customers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

class AddSlugToCustomers < ActiveRecord::Migration[7.0]
def change
change_table :customers, bulk: true do |t|
t.string :slug
t.bigint :sequential_id
safety_assured do
change_table :customers, bulk: true do |t|
t.string :slug
t.bigint :sequential_id
end
end

LagoApi::Application.load_tasks
Expand Down
12 changes: 7 additions & 5 deletions db/migrate/20220621090834_add_number_to_invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
class AddNumberToInvoices < ActiveRecord::Migration[7.0]
def change
# NOTE: sequential_id scope change we have to reset the column
change_table :invoices, bulk: true do |t|
t.remove_index :sequential_id
t.remove :sequential_id, type: :integer
safety_assured do
change_table :invoices, bulk: true do |t|
t.remove_index :sequential_id
t.remove :sequential_id, type: :integer

t.string :number, null: false, index: true, default: ''
t.integer :sequential_id, index: true
t.string :number, null: false, index: true, default: ''
t.integer :sequential_id, index: true
end
end
end
end
2 changes: 1 addition & 1 deletion db/migrate/20220705155228_add_unaccent_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class AddUnaccentExtension < ActiveRecord::Migration[7.0]
def up
execute 'CREATE EXTENSION unaccent'
safety_assured { execute 'CREATE EXTENSION unaccent' }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

class ChangeActiveStorageAttachmentsIdType < ActiveRecord::Migration[7.0]
def change
change_table :active_storage_attachments, bulk: true do |t|
t.remove :record_id # rubocop:disable Rails/ReversibleMigration
t.uuid :record_id
safety_assured do
change_table :active_storage_attachments, bulk: true do |t|
t.remove :record_id # rubocop:disable Rails/ReversibleMigration
t.uuid :record_id
end
end
end
end
8 changes: 5 additions & 3 deletions db/migrate/20220722123417_add_subscription_id_to_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ class AddSubscriptionIdToEvents < ActiveRecord::Migration[7.0]
def change
remove_index :events, %i[organization_id transaction_id]

add_reference :events, :subscription, type: :uuid, foreign_key: true
add_index :events, %i[subscription_id code]
add_index :events, %i[subscription_id transaction_id], unique: true
safety_assured do
add_reference :events, :subscription, type: :uuid, foreign_key: true
add_index :events, %i[subscription_id code]
add_index :events, %i[subscription_id transaction_id], unique: true
end
end
end
4 changes: 3 additions & 1 deletion db/migrate/20220725152220_add_unique_id_to_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
class AddUniqueIdToSubscriptions < ActiveRecord::Migration[7.0]
def up
add_column :subscriptions, :unique_id, :string
change_column_null :subscriptions, :unique_id, false
safety_assured do
change_column_null :subscriptions, :unique_id, false
end
end

def down
Expand Down
4 changes: 3 additions & 1 deletion db/migrate/20220727132848_create_invoice_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def change

t.timestamps
end
remove_reference :invoices, :subscription, index: true, foreign_key: true
safety_assured do
remove_reference :invoices, :subscription, index: true, foreign_key: true
end
end
end
4 changes: 3 additions & 1 deletion db/migrate/20220727161448_add_customer_to_invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class AddCustomerToInvoices < ActiveRecord::Migration[7.0]
def change
add_reference :invoices, :customer, type: :uuid, foreign_key: true, index: true
safety_assured do
add_reference :invoices, :customer, type: :uuid, foreign_key: true, index: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class AddAnniversaryFieldsToSubscriptions < ActiveRecord::Migration[7.0]
def change
add_column :subscriptions, :billing_time, :integer, null: false, default: 0
rename_column :subscriptions, :anniversary_date, :subscription_date
safety_assured do
rename_column :subscriptions, :anniversary_date, :subscription_date
end
end
end
10 changes: 6 additions & 4 deletions db/migrate/20220729062203_remove_invoice_columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

class RemoveInvoiceColumns < ActiveRecord::Migration[7.0]
def up
change_table :invoices, bulk: true do |t|
t.remove :from_date
t.remove :to_date
t.remove :charges_from_date
safety_assured do
change_table :invoices, bulk: true do |t|
t.remove :from_date
t.remove :to_date
t.remove :charges_from_date
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class AddInvoiceIdToWalletTransactions < ActiveRecord::Migration[7.0]
def change
add_reference :wallet_transactions, :invoice, type: :uuid, null: true, index: true, foreign_key: true
safety_assured do
add_reference :wallet_transactions, :invoice, type: :uuid, null: true, index: true, foreign_key: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class RemoveInvoiceFromWalletTransaction < ActiveRecord::Migration[7.0]
def change
remove_reference :wallet_transactions, :invoice, index: true, foreign_key: true
safety_assured do
remove_reference :wallet_transactions, :invoice, index: true, foreign_key: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class AddInvoiceableAndTypeToFees < ActiveRecord::Migration[7.0]
def change
add_column :fees, :fee_type, :integer
add_reference :fees, :invoiceable, type: :uuid, polymorphic: true
safety_assured do
add_reference :fees, :invoiceable, type: :uuid, polymorphic: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

class ChangePrecisionAndScaleForDecimalFields < ActiveRecord::Migration[7.0]
def up
change_table :wallets, bulk: true do |t|
t.change :rate_amount, :decimal, precision: 30, scale: 5
t.change :credits_balance, :decimal, precision: 30, scale: 5
t.change :balance, :decimal, precision: 30, scale: 5
t.change :consumed_credits, :decimal, precision: 30, scale: 5
t.change :consumed_amount, :decimal, precision: 30, scale: 5
end
safety_assured do
change_table :wallets, bulk: true do |t|
t.change :rate_amount, :decimal, precision: 30, scale: 5
t.change :credits_balance, :decimal, precision: 30, scale: 5
t.change :balance, :decimal, precision: 30, scale: 5
t.change :consumed_credits, :decimal, precision: 30, scale: 5
t.change :consumed_amount, :decimal, precision: 30, scale: 5
end

change_table :wallet_transactions, bulk: true do |t|
t.change :amount, :decimal, precision: 30, scale: 5
t.change :credit_amount, :decimal, precision: 30, scale: 5
change_table :wallet_transactions, bulk: true do |t|
t.change :amount, :decimal, precision: 30, scale: 5
t.change :credit_amount, :decimal, precision: 30, scale: 5
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

class RenameUniqueIdToExternalIdOnSubscriptions < ActiveRecord::Migration[7.0]
def change
rename_column :subscriptions, :unique_id, :external_id
add_index :subscriptions, :external_id
safety_assured do
rename_column :subscriptions, :unique_id, :external_id
add_index :subscriptions, :external_id
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class RenameCustomerIdToExternalIdOnCustomers < ActiveRecord::Migration[7.0]
def change
rename_column :customers, :customer_id, :external_id
safety_assured do
rename_column :customers, :customer_id, :external_id
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class AddWalletTransactionToInvoice < ActiveRecord::Migration[7.0]
def change
add_reference :wallet_transactions, :invoice, type: :uuid, null: true, index: true, foreign_key: true
safety_assured do
add_reference :wallet_transactions, :invoice, type: :uuid, null: true, index: true, foreign_key: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

class RenamePersistedMetricsIntoPersistedEvents < ActiveRecord::Migration[7.0]
def change
rename_table :persisted_metrics, :persisted_events
rename_index :persisted_events, :index_search_persisted_metrics, :index_search_persisted_events
safety_assured do
rename_table :persisted_metrics, :persisted_events
rename_index :persisted_events, :index_search_persisted_metrics, :index_search_persisted_events
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

class AddBillableMetricIdToPersistedEvents < ActiveRecord::Migration[7.0]
def change
add_reference :persisted_events, :billable_metric, type: :uuid
safety_assured do
add_reference :persisted_events, :billable_metric, type: :uuid

remove_index :persisted_events, name: :index_search_persisted_events # rubocop:disable Rails/ReversibleMigration
add_index :persisted_events,
[:customer_id, :external_subscription_id, :billable_metric_id],
name: :index_search_persisted_events
remove_index :persisted_events, name: :index_search_persisted_events # rubocop:disable Rails/ReversibleMigration
add_index :persisted_events,
[:customer_id, :external_subscription_id, :billable_metric_id],
name: :index_search_persisted_events
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

class AddMembershipStatusAndRevokedAt < ActiveRecord::Migration[7.0]
def change
change_table :memberships, bulk: true do |t|
t.integer :status, null: false, default: 0
t.datetime :revoked_at, null: true
safety_assured do
change_table :memberships, bulk: true do |t|
t.integer :status, null: false, default: 0
t.datetime :revoked_at, null: true
end
end
end
end
4 changes: 3 additions & 1 deletion db/migrate/20220916131538_add_parent_id_on_plans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class AddParentIdOnPlans < ActiveRecord::Migration[7.0]
def change
add_reference :plans, :parent, type: :uuid, null: true, index: true, foreign_key: {to_table: :plans}
safety_assured do
add_reference :plans, :parent, type: :uuid, null: true, index: true, foreign_key: {to_table: :plans}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

class AddCouponTypeAndPercentageRateToCoupons < ActiveRecord::Migration[7.0]
def change
change_table :coupons, bulk: true do |t|
t.integer :coupon_type, null: false, default: 0
t.decimal :percentage_rate, precision: 10, scale: 5
end
safety_assured do
change_table :coupons, bulk: true do |t|
t.integer :coupon_type, null: false, default: 0
t.decimal :percentage_rate, precision: 10, scale: 5
end

change_column_null :coupons, :amount_cents, true
change_column_null :coupons, :amount_currency, true
change_column_null :coupons, :amount_cents, true
change_column_null :coupons, :amount_currency, true

change_table :applied_coupons, bulk: true do |t|
t.decimal :percentage_rate, precision: 10, scale: 5
end
change_table :applied_coupons, bulk: true do |t|
t.decimal :percentage_rate, precision: 10, scale: 5
end

change_column_null :applied_coupons, :amount_cents, true
change_column_null :applied_coupons, :amount_currency, true
change_column_null :applied_coupons, :amount_cents, true
change_column_null :applied_coupons, :amount_currency, true
end
end
end
Loading

0 comments on commit 626427f

Please sign in to comment.