chore: init commit
in worker.../repo/GITFOLDER.zip is the .git folder.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
class CreateSchools < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :schools do |t|
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class CreateYears < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :years do |t|
|
||||
t.integer :year
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :years, :year, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateSchoolYears < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :school_years do |t|
|
||||
t.references :school, null: false, foreign_key: true
|
||||
t.references :year, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :school_years, [:school_id, :year_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateClassrooms < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :classrooms do |t|
|
||||
t.string :name
|
||||
t.references :year, null: false, foreign_key: true
|
||||
t.references :school, null: false, foreign_key: true
|
||||
t.string :grade
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DeviseCreateUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
## Database authenticatable
|
||||
t.string :email, null: true, default: ""
|
||||
t.string :username, null: false, default: ""
|
||||
t.string :encrypted_password, null: false, default: ""
|
||||
|
||||
## Recoverable
|
||||
t.string :reset_password_token
|
||||
t.datetime :reset_password_sent_at
|
||||
|
||||
## Rememberable
|
||||
t.datetime :remember_created_at
|
||||
|
||||
## Trackable
|
||||
# t.integer :sign_in_count, default: 0, null: false
|
||||
# t.datetime :current_sign_in_at
|
||||
# t.datetime :last_sign_in_at
|
||||
# t.string :current_sign_in_ip
|
||||
# t.string :last_sign_in_ip
|
||||
|
||||
## Confirmable
|
||||
# t.string :confirmation_token
|
||||
# t.datetime :confirmed_at
|
||||
# t.datetime :confirmation_sent_at
|
||||
# t.string :unconfirmed_email # Only if using reconfirmable
|
||||
|
||||
## Lockable
|
||||
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
||||
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
||||
# t.datetime :locked_at
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
add_index :users, :email, unique: true
|
||||
add_index :users, :username, unique: true
|
||||
add_index :users, :reset_password_token, unique: true
|
||||
# add_index :users, :confirmation_token, unique: true
|
||||
# add_index :users, :unlock_token, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,51 @@
|
||||
class CreateTableRelations < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_reference :users, :classroom, foreign_key: true
|
||||
|
||||
create_table :portfolios do |t|
|
||||
t.references :user, null: false, foreign_key: true
|
||||
t.float :cash_balance
|
||||
t.float :current_position
|
||||
t.json :transactions
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :portfolio_transactions do |t|
|
||||
t.references :portfolio, null: false, foreign_key: true
|
||||
t.integer :actor_id, null: false
|
||||
t.integer :transaction_type
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :companies do |t|
|
||||
t.string :company_name
|
||||
t.json :company_info
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :companies, :company_name, unique: true
|
||||
|
||||
create_table :stocks do |t|
|
||||
t.string :ticker
|
||||
t.json :price_info
|
||||
t.references :company, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :stocks, :ticker, unique: true
|
||||
|
||||
create_table :portfolio_stocks do |t|
|
||||
t.references :portfolio, null: false, foreign_key: true
|
||||
t.references :stock, null: false, foreign_key: true
|
||||
t.float :shares
|
||||
t.float :purchase_price
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :portfolio_stocks, [:portfolio_id, :stock_id], unique: true, name: "index_portfolio_stocks_on_portfolio_and_stock"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddStockToCompanies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_reference :companies, :stock, foreign_key: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,28 @@
|
||||
# standard:disable Rails/ReversibleMigration
|
||||
class RemoveCompanyAndAddToStock < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_reference :stocks, :company, foreign_key: true
|
||||
|
||||
drop_table :companies
|
||||
|
||||
add_column :stocks, :stock_exchange, :string
|
||||
|
||||
add_column :stocks, :company_name, :string
|
||||
add_column :stocks, :company_website, :string
|
||||
add_column :stocks, :description, :text
|
||||
add_column :stocks, :industry, :string
|
||||
add_column :stocks, :management, :text
|
||||
add_column :stocks, :employees, :integer
|
||||
add_column :stocks, :competitor_names, :text
|
||||
|
||||
add_column :stocks, :sales_growth, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :industry_avg_sales_growth, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :debt_to_equity, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :industry_avg_debt_to_equity, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :profit_margin, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :industry_avg_profit_margin, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :cash_flow, :decimal, precision: 15, scale: 2
|
||||
add_column :stocks, :debt, :decimal, precision: 15, scale: 2
|
||||
end
|
||||
end
|
||||
# rubocop:enable Rails/ReversibleMigration
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveUniqueIndexFromEmail < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_index :users, :email
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveActorIdFromPortfolioTransactions < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_reference :portfolio_transactions, :actor
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddAmountToPortfolioTransactions < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :portfolio_transactions, :amount, :decimal, precision: 8, scale: 2, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# standard:disable Rails/ReversibleMigration
|
||||
class RemoveCashBalanceFromPortfolios < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_column :portfolios, :cash_balance
|
||||
end
|
||||
end
|
||||
# rubocop:enable Rails/ReversibleMigration
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateOrders < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :orders do |t|
|
||||
t.references :user, null: false, foreign_key: true
|
||||
t.references :stock, null: false, foreign_key: true
|
||||
t.decimal :shares
|
||||
t.integer :status
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemovePriceInfoFromStocks < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_column :stocks, :price_info, :json
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddPriceToStocks < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :stocks, :price, :decimal
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
# standard:disable Rails/ReversibleMigrationMethodDefinition
|
||||
class CreateDelayedJobs < ActiveRecord::Migration[7.1]
|
||||
def self.up
|
||||
create_table :delayed_jobs do |table|
|
||||
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
|
||||
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
|
||||
table.text :handler, null: false # YAML-encoded string of the object that will do work
|
||||
table.text :last_error # reason for last failure (See Note below)
|
||||
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
|
||||
table.datetime :locked_at # Set when a client is working on this object
|
||||
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
||||
table.string :locked_by # Who is working on this object (if locked)
|
||||
table.string :queue # The name of the queue this job is in
|
||||
table.timestamps null: true
|
||||
end
|
||||
|
||||
add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :delayed_jobs
|
||||
end
|
||||
end
|
||||
# rubocop:enable Rails/ReversibleMigrationMethodDefinition
|
||||
@@ -0,0 +1,9 @@
|
||||
# standard:disable Rails/ReversibleMigration
|
||||
|
||||
class ChangeFloatToBigDecimalPortfolioStocks < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
change_column :portfolio_stocks, :shares, :decimal, precision: 15, scale: 2
|
||||
change_column :portfolio_stocks, :purchase_price, :decimal, precision: 15, scale: 2
|
||||
end
|
||||
end
|
||||
# rubocop:enable Rails/ReversibleMigration
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddPortfolioStockAndTransactionToOrder < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_reference :orders, :portfolio_stock, null: true, foreign_key: true
|
||||
add_reference :orders, :portfolio_transaction, null: true, foreign_key: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
# standard:disable Rails/ReversibleMigration
|
||||
class RemovePortfolioStocksIndex < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_index :portfolio_stocks, name: "index_portfolio_stocks_on_portfolio_and_stock"
|
||||
|
||||
add_index :portfolio_stocks, [:portfolio_id, :stock_id], name: "index_portfolio_stocks_on_portfolio_and_stock"
|
||||
end
|
||||
end
|
||||
# rubocop:enable Rails/ReversibleMigration
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddAdminToUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :users, :admin, :boolean, default: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNotNullConstraintToYearOnYears < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
change_column_null :years, :year, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
class RenameAmountToAmountCentsOnPortfolioTransactions < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
rename_column(:portfolio_transactions, :amount, :amount_cents)
|
||||
change_column(
|
||||
:portfolio_transactions,
|
||||
:amount_cents,
|
||||
:integer,
|
||||
null: false
|
||||
)
|
||||
end
|
||||
|
||||
dir.down do
|
||||
rename_column(:portfolio_transactions, :amount_cents, :amount)
|
||||
change_column(
|
||||
:portfolio_transactions,
|
||||
:amount,
|
||||
:decimal,
|
||||
precision: 15,
|
||||
scale: 2,
|
||||
null: false
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNotNullConstraintToTransactionTypeOnProtfolioTransactions < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
change_column_null(:portfolio_transactions, :transaction_type, false)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
class ChangePriceToPriceCentsOnStocks < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
rename_column :stocks, :price, :price_cents
|
||||
change_column :stocks, :price_cents, :integer
|
||||
end
|
||||
|
||||
dir.down do
|
||||
rename_column :stocks, :price_cents, :price
|
||||
change_column :stocks, :price, :decimal
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSchoolYearRefToClassrooms < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_reference :classrooms, :school_year, foreign_key: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class RemoveYearAndSchoolFromClassrooms < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
remove_reference :classrooms, :year, foreign_key: true
|
||||
remove_reference :classrooms, :school, foreign_key: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddUniqueIndexToUsersEmail < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_index :users, :email, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class ChangeYearColumnToNameAndUpdateType < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
rename_column :years, :year, :name
|
||||
change_column :years, :name, :string, null: false
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :years, :name, :integer
|
||||
rename_column :years, :name, :year
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Adds a type column to the users table to support STI
|
||||
class AddTypeToUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :users, :type, :string, default: "User", null: false
|
||||
change_column_null :users, :type, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
class FixStudentEmailConstraints < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
# Remove the existing unique index on email
|
||||
remove_index :users, :email if index_exists?(:users, :email)
|
||||
|
||||
# Change email column to allow null and remove default empty string
|
||||
change_column :users, :email, :string, null: true, default: nil
|
||||
|
||||
# Update existing empty string emails to null for students
|
||||
User.where(email: "", type: "Student").update_all(email: nil)
|
||||
|
||||
# Create a partial unique index that only applies to non-null, non-empty emails
|
||||
add_index :users, :email, unique: true, where: "email IS NOT NULL AND email != ''"
|
||||
end
|
||||
|
||||
def down
|
||||
# Remove the partial unique index
|
||||
remove_index :users, :email if index_exists?(:users, :email)
|
||||
|
||||
# Restore the original email column settings
|
||||
change_column :users, :email, :string, null: false, default: ""
|
||||
|
||||
# Update null emails back to empty strings
|
||||
User.where(email: nil).update_all(email: "")
|
||||
|
||||
# Restore the original unique index
|
||||
add_index :users, :email, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveTransactionsFromPortfolios < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
safety_assured { remove_column :portfolios, :transactions, :json }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class CreateQuarters < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :quarters do |t|
|
||||
t.string :name
|
||||
t.references :school_year, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateGradeBooks < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :grade_books do |t|
|
||||
t.references :quarter, null: false, foreign_key: true
|
||||
t.references :classroom, null: false, foreign_key: true
|
||||
|
||||
t.string :status, null: false, default: 'draft'
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :grade_books, [:quarter_id, :classroom_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class CreateGradeEntries < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :grade_entries do |t|
|
||||
t.references :grade_book, null: false, foreign_key: true
|
||||
t.references :user, null: false, foreign_key: true
|
||||
|
||||
t.string :math_grade, null: true
|
||||
t.string :reading_grade, null: true
|
||||
t.bigint :days_missed, null: false, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :grade_entries, [:grade_book_id, :user_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNumberToQuarters < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :quarters, :number, :integer, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIndexToNumberOnQuarters < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :quarters, [:school_year_id, :number], unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateTeacherClassrooms < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :teacher_classrooms do |t|
|
||||
t.references :teacher, null: false, foreign_key: { to_table: :users }
|
||||
t.references :classroom, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :teacher_classrooms, [:teacher_id, :classroom_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class SetStatusDefaulOnOrders < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
change_column_default :orders, :status, 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddPerfectWeeksToGradeEntries < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :grade_entries, :perfect_weeks, :bigint
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveMissedDaysFromGradeEntries < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
safety_assured { remove_column :grade_entries, :days_missed, :bigint }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddAttendanceDaysToGradeEntries < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :grade_entries, :attendance_days, :bigint
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemovePerfectWeeksFromGradeEntries < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
safety_assured { remove_column :grade_entries, :perfect_weeks, :bigint }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddActionToOrders < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :orders, :action, :string, null: false, default: "sell"
|
||||
|
||||
change_column_default :orders, :action, from: "sell", to: nil
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddArchivedToStocks < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :stocks, :archived, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class ConvertGradeToInteger < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
safety_assured { remove_column :classrooms, :grade, :string }
|
||||
add_column :classrooms, :grade, :integer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddTransactionFeeToOrders < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :orders, :transaction_fee_cents, :integer, null: false, default: 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddReasonToPortfolioTransaction < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :portfolio_transactions, :reason, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDiscardedAtToUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :users, :discarded_at, :datetime
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddIndexDiscardedAtToUsers < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :users, :discarded_at, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddIsPerfectAttendanceToGradeEntries < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :grade_entries, :is_perfect_attendance, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class DropTransactionFeeFromOrders < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
safety_assured do
|
||||
remove_column :orders, :transaction_fee_cents, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddYesterdayPriceCentsToStocks < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :stocks, :yesterday_price_cents, :integer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNameToUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :users, :name, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreatePortfolioSnapshots < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :portfolio_snapshots do |t|
|
||||
t.references :portfolio, null: false, foreign_key: true
|
||||
t.date :date, null: false
|
||||
t.integer :worth_cents, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :portfolio_snapshots, [:portfolio_id, :date], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class CreateAnnouncments < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :announcements do |t|
|
||||
t.string :title
|
||||
t.text :body
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
# This migration comes from active_storage (originally 20170806125915)
|
||||
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# Use Active Record's configured type for primary and foreign keys
|
||||
primary_key_type, foreign_key_type = primary_and_foreign_key_types
|
||||
|
||||
create_table :active_storage_blobs, id: primary_key_type do |t|
|
||||
t.string :key, null: false
|
||||
t.string :filename, null: false
|
||||
t.string :content_type
|
||||
t.text :metadata
|
||||
t.string :service_name, null: false
|
||||
t.bigint :byte_size, null: false
|
||||
t.string :checksum
|
||||
|
||||
if connection.supports_datetime_with_precision?
|
||||
t.datetime :created_at, precision: 6, null: false
|
||||
else
|
||||
t.datetime :created_at, null: false
|
||||
end
|
||||
|
||||
t.index [ :key ], unique: true
|
||||
end
|
||||
|
||||
create_table :active_storage_attachments, id: primary_key_type do |t|
|
||||
t.string :name, null: false
|
||||
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
|
||||
t.references :blob, null: false, type: foreign_key_type
|
||||
|
||||
if connection.supports_datetime_with_precision?
|
||||
t.datetime :created_at, precision: 6, null: false
|
||||
else
|
||||
t.datetime :created_at, null: false
|
||||
end
|
||||
|
||||
t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
|
||||
t.foreign_key :active_storage_blobs, column: :blob_id
|
||||
end
|
||||
|
||||
create_table :active_storage_variant_records, id: primary_key_type do |t|
|
||||
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
|
||||
t.string :variation_digest, null: false
|
||||
|
||||
t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
|
||||
t.foreign_key :active_storage_blobs, column: :blob_id
|
||||
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,0 +1,26 @@
|
||||
# This migration comes from action_text (originally 20180528164100)
|
||||
class CreateActionTextTables < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
# Use Active Record's configured type for primary and foreign keys
|
||||
primary_key_type, foreign_key_type = primary_and_foreign_key_types
|
||||
|
||||
create_table :action_text_rich_texts, id: primary_key_type do |t|
|
||||
t.string :name, null: false
|
||||
t.text :body, size: :long
|
||||
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
|
||||
|
||||
t.timestamps
|
||||
|
||||
t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
|
||||
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,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DropDelayedJobsTable < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
drop_table :delayed_jobs, if_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
create_table "delayed_jobs" do |t|
|
||||
t.integer "priority", default: 0, null: false
|
||||
t.integer "attempts", default: 0, null: false
|
||||
t.text "handler", null: false
|
||||
t.text "last_error"
|
||||
t.datetime "run_at"
|
||||
t.datetime "locked_at"
|
||||
t.datetime "failed_at"
|
||||
t.string "locked_by"
|
||||
t.string "queue"
|
||||
t.timestamps null: true
|
||||
|
||||
t.index ["priority", "run_at"], name: "delayed_jobs_priority"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIndexToAnnouncementsCreatedAt < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :announcements, :created_at, order: { created_at: :desc }, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,131 @@
|
||||
class CreateSolidQueue < ActiveRecord::Migration[8.0]
|
||||
safety_assured do
|
||||
create_table "solid_queue_blocked_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.string "queue_name", null: false
|
||||
t.integer "priority", default: 0, null: false
|
||||
t.string "concurrency_key", null: false
|
||||
t.datetime "expires_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "concurrency_key", "priority", "job_id" ], name: "index_solid_queue_blocked_executions_for_release"
|
||||
t.index [ "expires_at", "concurrency_key" ], name: "index_solid_queue_blocked_executions_for_maintenance"
|
||||
t.index [ "job_id" ], name: "index_solid_queue_blocked_executions_on_job_id", unique: true
|
||||
end
|
||||
|
||||
create_table "solid_queue_claimed_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.bigint "process_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "job_id" ], name: "index_solid_queue_claimed_executions_on_job_id", unique: true
|
||||
t.index [ "process_id", "job_id" ], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id"
|
||||
end
|
||||
|
||||
create_table "solid_queue_failed_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.text "error"
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "job_id" ], name: "index_solid_queue_failed_executions_on_job_id", unique: true
|
||||
end
|
||||
|
||||
create_table "solid_queue_jobs", force: :cascade do |t|
|
||||
t.string "queue_name", null: false
|
||||
t.string "class_name", null: false
|
||||
t.text "arguments"
|
||||
t.integer "priority", default: 0, null: false
|
||||
t.string "active_job_id"
|
||||
t.datetime "scheduled_at"
|
||||
t.datetime "finished_at"
|
||||
t.string "concurrency_key"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index [ "active_job_id" ], name: "index_solid_queue_jobs_on_active_job_id"
|
||||
t.index [ "class_name" ], name: "index_solid_queue_jobs_on_class_name"
|
||||
t.index [ "finished_at" ], name: "index_solid_queue_jobs_on_finished_at"
|
||||
t.index [ "queue_name", "finished_at" ], name: "index_solid_queue_jobs_for_filtering"
|
||||
t.index [ "scheduled_at", "finished_at" ], name: "index_solid_queue_jobs_for_alerting"
|
||||
end
|
||||
|
||||
create_table "solid_queue_pauses", force: :cascade do |t|
|
||||
t.string "queue_name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "queue_name" ], name: "index_solid_queue_pauses_on_queue_name", unique: true
|
||||
end
|
||||
|
||||
create_table "solid_queue_processes", force: :cascade do |t|
|
||||
t.string "kind", null: false
|
||||
t.datetime "last_heartbeat_at", null: false
|
||||
t.bigint "supervisor_id"
|
||||
t.integer "pid", null: false
|
||||
t.string "hostname"
|
||||
t.text "metadata"
|
||||
t.datetime "created_at", null: false
|
||||
t.string "name", null: false
|
||||
t.index [ "last_heartbeat_at" ], name: "index_solid_queue_processes_on_last_heartbeat_at"
|
||||
t.index [ "name", "supervisor_id" ], name: "index_solid_queue_processes_on_name_and_supervisor_id", unique: true
|
||||
t.index [ "supervisor_id" ], name: "index_solid_queue_processes_on_supervisor_id"
|
||||
end
|
||||
|
||||
create_table "solid_queue_ready_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.string "queue_name", null: false
|
||||
t.integer "priority", default: 0, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "job_id" ], name: "index_solid_queue_ready_executions_on_job_id", unique: true
|
||||
t.index [ "priority", "job_id" ], name: "index_solid_queue_poll_all"
|
||||
t.index [ "queue_name", "priority", "job_id" ], name: "index_solid_queue_poll_by_queue"
|
||||
end
|
||||
|
||||
create_table "solid_queue_recurring_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.string "task_key", null: false
|
||||
t.datetime "run_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "job_id" ], name: "index_solid_queue_recurring_executions_on_job_id", unique: true
|
||||
t.index [ "task_key", "run_at" ], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true
|
||||
end
|
||||
|
||||
create_table "solid_queue_recurring_tasks", force: :cascade do |t|
|
||||
t.string "key", null: false
|
||||
t.string "schedule", null: false
|
||||
t.string "command", limit: 2048
|
||||
t.string "class_name"
|
||||
t.text "arguments"
|
||||
t.string "queue_name"
|
||||
t.integer "priority", default: 0
|
||||
t.boolean "static", default: true, null: false
|
||||
t.text "description"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index [ "key" ], name: "index_solid_queue_recurring_tasks_on_key", unique: true
|
||||
t.index [ "static" ], name: "index_solid_queue_recurring_tasks_on_static"
|
||||
end
|
||||
|
||||
create_table "solid_queue_scheduled_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.string "queue_name", null: false
|
||||
t.integer "priority", default: 0, null: false
|
||||
t.datetime "scheduled_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index [ "job_id" ], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true
|
||||
t.index [ "scheduled_at", "priority", "job_id" ], name: "index_solid_queue_dispatch_all"
|
||||
end
|
||||
|
||||
create_table "solid_queue_semaphores", force: :cascade do |t|
|
||||
t.string "key", null: false
|
||||
t.integer "value", default: 1, null: false
|
||||
t.datetime "expires_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index [ "expires_at" ], name: "index_solid_queue_semaphores_on_expires_at"
|
||||
t.index [ "key", "value" ], name: "index_solid_queue_semaphores_on_key_and_value"
|
||||
t.index [ "key" ], name: "index_solid_queue_semaphores_on_key", unique: true
|
||||
end
|
||||
|
||||
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDescriptionToPortfolioTransactions < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :portfolio_transactions, :description, :text
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddArchivedToClassrooms < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :classrooms, :archived, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddTradingEnabledToClassrooms < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :classrooms, :trading_enabled, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
class ConvertPortfolioTransactionReasonToEnum < ActiveRecord::Migration[8.1]
|
||||
def up
|
||||
add_column :portfolio_transactions, :reason_enum, :integer
|
||||
|
||||
safety_assured do
|
||||
execute <<-SQL
|
||||
UPDATE portfolio_transactions SET reason_enum = 0 WHERE reason = 'Earnings from Math';
|
||||
UPDATE portfolio_transactions SET reason_enum = 1 WHERE reason = 'Earnings from Reading';
|
||||
UPDATE portfolio_transactions SET reason_enum = 2 WHERE reason = 'Earnings from Attendance';
|
||||
UPDATE portfolio_transactions SET reason_enum = 3 WHERE reason = 'Earnings from Grades';
|
||||
UPDATE portfolio_transactions SET reason_enum = 4 WHERE reason = 'Transaction Fees';
|
||||
UPDATE portfolio_transactions SET reason_enum = 5 WHERE reason = 'Award';
|
||||
UPDATE portfolio_transactions SET reason_enum = 6 WHERE reason = 'Administrative Adjustment';
|
||||
SQL
|
||||
end
|
||||
|
||||
if PortfolioTransaction.where.not(reason: nil).where(reason_enum: nil).exists?
|
||||
raise "Migration Failed: Some records were not migrated! Check for unmapped 'reason' strings."
|
||||
end
|
||||
|
||||
safety_assured do
|
||||
remove_column :portfolio_transactions, :reason
|
||||
end
|
||||
|
||||
safety_assured do
|
||||
rename_column :portfolio_transactions, :reason_enum, :reason
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :portfolio_transactions, :reason_string, :string
|
||||
|
||||
safety_assured do
|
||||
execute <<-SQL
|
||||
UPDATE portfolio_transactions SET reason_string = 'Earnings from Math' WHERE reason = 0;
|
||||
UPDATE portfolio_transactions SET reason_string = 'Earnings from Reading' WHERE reason = 1;
|
||||
UPDATE portfolio_transactions SET reason_string = 'Earnings from Attendance' WHERE reason = 2;
|
||||
UPDATE portfolio_transactions SET reason_string = 'Earnings from Grades' WHERE reason = 3;
|
||||
UPDATE portfolio_transactions SET reason_string = 'Transaction Fees' WHERE reason = 4;
|
||||
UPDATE portfolio_transactions SET reason_string = 'Award' WHERE reason = 5;
|
||||
UPDATE portfolio_transactions SET reason_string = 'Administrative Adjustment' WHERE reason = 6;
|
||||
SQL
|
||||
end
|
||||
|
||||
safety_assured do
|
||||
remove_column :portfolio_transactions, :reason
|
||||
end
|
||||
|
||||
safety_assured do
|
||||
rename_column :portfolio_transactions, :reason_string, :reason
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddFeaturedToAnnouncements < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_column :announcements, :featured, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
class CreateGrades < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :grades do |t|
|
||||
t.string :name, null: false
|
||||
t.integer :level, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :grades, :level, unique: true
|
||||
add_index :grades, :name, unique: true
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
grades = [
|
||||
{ name: "Kindergarten", level: 0 },
|
||||
{ name: "1st Grade", level: 1 },
|
||||
{ name: "2nd Grade", level: 2 },
|
||||
{ name: "3rd Grade", level: 3 },
|
||||
{ name: "4th Grade", level: 4 },
|
||||
{ name: "5th Grade", level: 5 },
|
||||
{ name: "6th Grade", level: 6 },
|
||||
{ name: "7th Grade", level: 7 },
|
||||
{ name: "8th Grade", level: 8 },
|
||||
{ name: "9th Grade", level: 9 },
|
||||
{ name: "10th Grade", level: 10 },
|
||||
{ name: "11th Grade", level: 11 },
|
||||
{ name: "12th Grade", level: 12 },
|
||||
]
|
||||
|
||||
Grade.upsert_all(
|
||||
grades,
|
||||
unique_by: :level
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateClassroomGrades < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :classroom_grades do |t|
|
||||
t.references :classroom, null: false, foreign_key: true
|
||||
t.references :grade, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :classroom_grades, [:classroom_id, :grade_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddLastTradingDayToStocks < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_column :stocks, :last_trading_day, :date
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,39 @@
|
||||
class MigrateClassroomGradeToClassroomGrades < ActiveRecord::Migration[8.1]
|
||||
class Classroom < ActiveRecord::Base
|
||||
self.table_name = "classrooms"
|
||||
end
|
||||
|
||||
class Grade < ActiveRecord::Base
|
||||
self.table_name = "grades"
|
||||
end
|
||||
|
||||
class ClassroomGrade < ActiveRecord::Base
|
||||
self.table_name = "classroom_grades"
|
||||
end
|
||||
|
||||
def up
|
||||
Classroom.reset_column_information
|
||||
|
||||
Classroom.find_each do |classroom|
|
||||
grade_number = classroom.grade
|
||||
raise "Grade not found for classroom #{classroom.id}" unless grade_number
|
||||
|
||||
grade = Grade.find_by(level: grade_number)
|
||||
raise "Grade with level #{grade_number} not found" unless grade
|
||||
|
||||
classroom_grade = ClassroomGrade.create!(grade_id: grade.id, classroom_id: classroom.id)
|
||||
end
|
||||
|
||||
safety_assured { remove_column :classrooms, :grade }
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :classrooms, :grade, :integer
|
||||
Classroom.reset_column_information
|
||||
|
||||
Classroom.find_each do |classroom|
|
||||
level = classroom.classroom_grade&.grade&.level
|
||||
classroom.update_column(:grade, level) if level
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
class CreateClassroomEnrollments < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :classroom_enrollments do |t|
|
||||
t.references :student, null: false, foreign_key: { to_table: :users }
|
||||
t.references :classroom, null: false, foreign_key: true
|
||||
t.datetime :enrolled_at, null: false
|
||||
t.datetime :unenrolled_at
|
||||
t.boolean :primary, default: false, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :classroom_enrollments, [:student_id, :classroom_id, :enrolled_at],
|
||||
name: "index_enrollments_on_student_classroom_enrolled"
|
||||
add_index :classroom_enrollments, [:student_id, :primary],
|
||||
where: '"primary" = true',
|
||||
name: "index_enrollments_on_student_primary"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveCurrentPositionFromPortfolios < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
safety_assured { remove_column :portfolios, :current_position, :float }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class BackfillTeacherUsernameFromEmail < ActiveRecord::Migration[8.1]
|
||||
def up
|
||||
User.where(type: "Teacher").find_each do |teacher|
|
||||
teacher.update_column(:username, teacher.email) if teacher.email.present?
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
# No safe way to reverse — username values before migration are unknown
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddCascadeDeleteToQuartersSchoolYear < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
safety_assured do
|
||||
remove_foreign_key :quarters, :school_years
|
||||
add_foreign_key :quarters, :school_years, on_delete: :cascade
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user