mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
Subscription tests and domain (#2209)
* Save work * Subscriptions and trials domain * Store family ID on customer * Remove indirection of stripe calls * Test simplifications * Update brakeman * Fix stripe tests in CI * Update billing page to show subscription details * Remove legacy columns * Complete billing settings page * Fix hardcoded plan name * Handle subscriptions for self hosting mode * Lint fixes
This commit is contained in:
parent
8c10e87387
commit
5da4bb6dc3
40 changed files with 1041 additions and 233 deletions
46
db/migrate/20250502164951_create_subscriptions.rb
Normal file
46
db/migrate/20250502164951_create_subscriptions.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
class CreateSubscriptions < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :subscriptions, id: :uuid do |t|
|
||||
t.references :family, null: false, foreign_key: true, type: :uuid
|
||||
|
||||
t.string :status, null: false
|
||||
|
||||
t.string :stripe_id
|
||||
t.decimal :amount, precision: 19, scale: 4
|
||||
t.string :currency
|
||||
t.string :interval
|
||||
|
||||
t.datetime :current_period_ends_at
|
||||
t.datetime :trial_ends_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
if Rails.application.config.app_mode.managed?
|
||||
execute <<~SQL
|
||||
INSERT INTO subscriptions (family_id, status, trial_ends_at, created_at, updated_at)
|
||||
SELECT
|
||||
f.id,
|
||||
CASE
|
||||
WHEN f.trial_started_at IS NOT NULL THEN 'trialing'
|
||||
ELSE COALESCE(f.stripe_subscription_status, 'incomplete')
|
||||
END,
|
||||
CASE
|
||||
WHEN f.trial_started_at IS NOT NULL THEN f.trial_started_at + INTERVAL '14 days'
|
||||
ELSE NULL
|
||||
END,
|
||||
now(),
|
||||
now()
|
||||
FROM families f
|
||||
SQL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
remove_column :families, :stripe_subscription_status, :string
|
||||
remove_column :families, :trial_started_at, :datetime
|
||||
remove_column :families, :stripe_plan_id, :string
|
||||
end
|
||||
end
|
20
db/schema.rb
generated
20
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_05_01_172430) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_05_02_164951) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -222,15 +222,12 @@ ActiveRecord::Schema[7.2].define(version: 2025_05_01_172430) do
|
|||
t.datetime "updated_at", null: false
|
||||
t.string "currency", default: "USD"
|
||||
t.string "locale", default: "en"
|
||||
t.string "stripe_plan_id"
|
||||
t.string "stripe_customer_id"
|
||||
t.string "stripe_subscription_status", default: "incomplete"
|
||||
t.string "date_format", default: "%m-%d-%Y"
|
||||
t.string "country", default: "US"
|
||||
t.datetime "last_synced_at"
|
||||
t.string "timezone"
|
||||
t.boolean "data_enrichment_enabled", default: false
|
||||
t.datetime "trial_started_at"
|
||||
t.boolean "early_access", default: false
|
||||
end
|
||||
|
||||
|
@ -575,6 +572,20 @@ ActiveRecord::Schema[7.2].define(version: 2025_05_01_172430) do
|
|||
t.index ["currency_code"], name: "index_stock_exchanges_on_currency_code"
|
||||
end
|
||||
|
||||
create_table "subscriptions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "family_id", null: false
|
||||
t.string "status", null: false
|
||||
t.string "stripe_id"
|
||||
t.decimal "amount", precision: 19, scale: 4
|
||||
t.string "currency"
|
||||
t.string "interval"
|
||||
t.datetime "current_period_ends_at"
|
||||
t.datetime "trial_ends_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["family_id"], name: "index_subscriptions_on_family_id"
|
||||
end
|
||||
|
||||
create_table "syncs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "syncable_type", null: false
|
||||
t.uuid "syncable_id", null: false
|
||||
|
@ -742,6 +753,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_05_01_172430) do
|
|||
add_foreign_key "security_prices", "securities"
|
||||
add_foreign_key "sessions", "impersonation_sessions", column: "active_impersonator_session_id"
|
||||
add_foreign_key "sessions", "users"
|
||||
add_foreign_key "subscriptions", "families"
|
||||
add_foreign_key "syncs", "syncs", column: "parent_id"
|
||||
add_foreign_key "taggings", "tags"
|
||||
add_foreign_key "tags", "families"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue