Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.97 KB | None | 0 0
  1. class UpdatePlansModelAndDataAndLinkUser < ActiveRecord::Migration[5.0]
  2.   def change
  3.     # Remove old table
  4.     drop_table :plans
  5.  
  6.     # Remove incorrect constrains
  7.     remove_column   :users, :plan_id
  8.     remove_column   :users, :expires_on
  9.     remove_column   :users, :is_demo
  10.  
  11.     # Remove incorrect constrains
  12.     remove_column :subscriptions, :plan_id
  13.  
  14.     create_table :plans do |t|
  15.       t.integer :position
  16.       t.integer :max_cards
  17.       t.string  :plan_id
  18.       t.timestamps
  19.     end
  20.  
  21.     add_column :subscriptions, :expires_on, :date
  22.  
  23.     # Redo correct constrains
  24.     add_reference :subscriptions, :plan, foreign_key: true
  25.     add_reference :users, :subscription, foreign_key: true
  26.  
  27.     Plan.create(position: 1,  plan_id: 'free',     max_cards: 1)
  28.     Plan.create(position: 2,  plan_id: 'basic',    max_cards: 1)
  29.     Plan.create(position: 3,  plan_id: 'plus',     max_cards: 1)
  30.     Plan.create(position: 4,  plan_id: 'premium',  max_cards: 3)
  31.   end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement