From 207ed0156aa9cae857177c41d7e20bba216e31a5 Mon Sep 17 00:00:00 2001 From: fiveNinePlusR Date: Fri, 6 Dec 2024 20:23:32 -0800 Subject: [PATCH] Fix migrations and use env vars for db name if set --- config/database.yml | 4 ++-- .../20241126054618_add_submission_counts_to_users.rb | 10 +++++----- .../20241128052830_fix_users_table_defaults.rb | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/config/database.yml b/config/database.yml index e58db357..0377592c 100644 --- a/config/database.yml +++ b/config/database.yml @@ -5,12 +5,12 @@ default: &default development: <<: *default - database: pbm_dev + database: <%= ENV.fetch("DATABASE", 'pbm_dev') %> host: localhost test: <<: *default - database: pbm_test + database: <%= ENV.fetch("DATABASE", 'pbm_test') %> staging: url: <%= ENV["DATABASE_URL"] %> diff --git a/db/migrate/20241126054618_add_submission_counts_to_users.rb b/db/migrate/20241126054618_add_submission_counts_to_users.rb index 8e2711a2..9fae6982 100644 --- a/db/migrate/20241126054618_add_submission_counts_to_users.rb +++ b/db/migrate/20241126054618_add_submission_counts_to_users.rb @@ -1,9 +1,9 @@ class AddSubmissionCountsToUsers < ActiveRecord::Migration[7.2] def change - add_column :users, :num_machines_added, :integer - add_column :users, :num_machines_removed, :integer - add_column :users, :num_locations_suggested, :integer - add_column :users, :num_lmx_comments_left, :integer - add_column :users, :num_msx_scores_added, :integer + add_column :users, :num_machines_added, :integer, default: 0 + add_column :users, :num_machines_removed, :integer, default: 0 + add_column :users, :num_locations_suggested, :integer, default: 0 + add_column :users, :num_lmx_comments_left, :integer, default: 0 + add_column :users, :num_msx_scores_added, :integer, default: 0 end end diff --git a/db/migrate/20241128052830_fix_users_table_defaults.rb b/db/migrate/20241128052830_fix_users_table_defaults.rb index e1166a41..7f8cb808 100644 --- a/db/migrate/20241128052830_fix_users_table_defaults.rb +++ b/db/migrate/20241128052830_fix_users_table_defaults.rb @@ -1,10 +1,10 @@ class FixUsersTableDefaults < ActiveRecord::Migration[7.2] def change - change_column_default :users, :num_machines_added, default: 0 - change_column_default :users, :num_machines_removed, default: 0 - change_column_default :users, :num_locations_suggested, default: 0 - change_column_default :users, :num_lmx_comments_left, default: 0 - change_column_default :users, :num_msx_scores_added, default: 0 - change_column_default :users, :user_submissions_count, default: 0 + change_column_default :users, :num_machines_added, from: nil, to: 0 + change_column_default :users, :num_machines_removed, from: nil, to: 0 + change_column_default :users, :num_locations_suggested, from: nil, to: 0 + change_column_default :users, :num_lmx_comments_left, from: nil, to: 0 + change_column_default :users, :num_msx_scores_added, from: nil, to: 0 + change_column_default :users, :user_submissions_count, from: nil, to: 0 end end