1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(bug) unable to run rails db:migrate if the database is empty

This commit is contained in:
Du Peng 2024-10-25 17:36:32 +02:00
parent 2ea4296e3c
commit 8a308953b7
4 changed files with 62 additions and 50 deletions

View File

@ -2,6 +2,8 @@
## Next release ## Next release
- Fix a bug: unable to run rails db:migrate if the database is empty
## v6.3.34 2024 October 21 ## v6.3.34 2024 October 21
- Fix a bug: unable to run open project update task - Fix a bug: unable to run open project update task

View File

@ -3,6 +3,8 @@
class MigrateSettingsValueToHistoryValues < ActiveRecord::Migration[4.2] class MigrateSettingsValueToHistoryValues < ActiveRecord::Migration[4.2]
def up def up
user = User.admins.first user = User.admins.first
return unless user
Setting.all.each do |setting| Setting.all.each do |setting|
hv = HistoryValue.new( hv = HistoryValue.new(
setting: setting, setting: setting,

View File

@ -96,6 +96,7 @@ class CreateNotificationTypes < ActiveRecord::Migration[5.2]
add_index :notification_types, :name, unique: true add_index :notification_types, :name, unique: true
if NotificationType.count > 0
# Records previous notification types # Records previous notification types
NOTIFICATIONS_TYPES.each do |notification_type| NOTIFICATIONS_TYPES.each do |notification_type|
NotificationType.create!( NotificationType.create!(
@ -108,6 +109,7 @@ class CreateNotificationTypes < ActiveRecord::Migration[5.2]
last_id = NotificationType.order(:id).last.id last_id = NotificationType.order(:id).last.id
execute "SELECT setval('public.notification_types_id_seq', #{last_id})" execute "SELECT setval('public.notification_types_id_seq', #{last_id})"
end
add_foreign_key :notifications, :notification_types add_foreign_key :notifications, :notification_types
end end

View File

@ -36,6 +36,7 @@ class AddLabelI18nPathToStatisticTables < ActiveRecord::Migration[7.0]
# StatisticField # StatisticField
if StatisticField.count > 0
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_subscription.id).update!(label: nil, label_i18n_path: 'statistics.group') StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_subscription.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'spaceDates', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.space_dates') StatisticField.find_by!(key: 'spaceDates', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.space_dates')
@ -68,8 +69,10 @@ class AddLabelI18nPathToStatisticTables < ActiveRecord::Migration[7.0]
StatisticField.find_by!(key: 'userId', statistic_index_id: statistic_index_user.id).update!(label: nil, label_i18n_path: 'statistics.user_id') StatisticField.find_by!(key: 'userId', statistic_index_id: statistic_index_user.id).update!(label: nil, label_i18n_path: 'statistics.user_id')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_order.id).update!(label: nil, label_i18n_path: 'statistics.group') StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_order.id).update!(label: nil, label_i18n_path: 'statistics.group')
end
# StatisticType # StatisticType
if StatisticType.count > 0
StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.bookings') StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.bookings')
StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.hours_number') StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
@ -89,11 +92,14 @@ class AddLabelI18nPathToStatisticTables < ActiveRecord::Migration[7.0]
StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.hours_number') StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
StatisticType.find_by!(key: 'store', statistic_index_id: statistic_index_order.id).update!(label: nil, label_i18n_path: 'statistics.store') StatisticType.find_by!(key: 'store', statistic_index_id: statistic_index_order.id).update!(label: nil, label_i18n_path: 'statistics.store')
end
# StatisticSubType # StatisticSubType
if StatisticSubType.count > 0
StatisticSubType.find_by!(key: 'created').update!(label: nil, label_i18n_path: 'statistics.account_creation') StatisticSubType.find_by!(key: 'created').update!(label: nil, label_i18n_path: 'statistics.account_creation')
StatisticSubType.find_by!(key: 'published').update!(label: nil, label_i18n_path: 'statistics.project_publication') StatisticSubType.find_by!(key: 'published').update!(label: nil, label_i18n_path: 'statistics.project_publication')
StatisticSubType.find_by!(key: 'paid-processed').update!(label: nil, label_i18n_path: 'statistics.paid-rocessed') StatisticSubType.find_by!(key: 'paid-processed').update!(label: nil, label_i18n_path: 'statistics.paid-rocessed')
StatisticSubType.find_by!(key: 'aborted').update!(label: nil, label_i18n_path: 'statistics.aborted') StatisticSubType.find_by!(key: 'aborted').update!(label: nil, label_i18n_path: 'statistics.aborted')
end end
end
end end