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
- Fix a bug: unable to run rails db:migrate if the database is empty
## v6.3.34 2024 October 21
- Fix a bug: unable to run open project update task

View File

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

View File

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

View File

@ -36,64 +36,70 @@ class AddLabelI18nPathToStatisticTables < ActiveRecord::Migration[7.0]
# StatisticField
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_subscription.id).update!(label: nil, label_i18n_path: 'statistics.group')
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: 'spaceDates', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.space_dates')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_space.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: 'groupName', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'machineDates', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.machine_dates')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'machineDates', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.machine_dates')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'trainingId', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.training_id')
StatisticField.find_by!(key: 'trainingDate', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.training_date')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'trainingId', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.training_id')
StatisticField.find_by!(key: 'trainingDate', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.training_date')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'name', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_name')
StatisticField.find_by!(key: 'eventId', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_id')
StatisticField.find_by!(key: 'eventDate', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_date')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'eventTheme', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_theme')
StatisticField.find_by!(key: 'ageRange', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.age_range')
StatisticField.find_by!(key: 'name', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_name')
StatisticField.find_by!(key: 'eventId', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_id')
StatisticField.find_by!(key: 'eventDate', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_date')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'eventTheme', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.event_theme')
StatisticField.find_by!(key: 'ageRange', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.age_range')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_account.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'groupName', statistic_index_id: statistic_index_account.id).update!(label: nil, label_i18n_path: 'statistics.group')
StatisticField.find_by!(key: 'themes', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.themes')
StatisticField.find_by!(key: 'components', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.components')
StatisticField.find_by!(key: 'machines', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.machines')
StatisticField.find_by!(key: 'status', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.project_status')
StatisticField.find_by!(key: 'name', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.project_name')
StatisticField.find_by!(key: 'projectUserNames', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.project_user_names')
StatisticField.find_by!(key: 'themes', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.themes')
StatisticField.find_by!(key: 'components', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.components')
StatisticField.find_by!(key: 'machines', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.machines')
StatisticField.find_by!(key: 'status', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.project_status')
StatisticField.find_by!(key: 'name', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.project_name')
StatisticField.find_by!(key: 'projectUserNames', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.project_user_names')
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.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')
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: 'hour', statistic_index_id: statistic_index_machine.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.bookings')
StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.bookings')
StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_training.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.tickets_number')
StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.tickets_number')
StatisticType.find_by!(key: 'hour', statistic_index_id: statistic_index_event.id).update!(label: nil, label_i18n_path: 'statistics.hours_number')
StatisticType.find_by!(key: 'member', statistic_index_id: statistic_index_account.id).update!(label: nil, label_i18n_path: 'statistics.users')
StatisticType.find_by!(key: 'member', statistic_index_id: statistic_index_account.id).update!(label: nil, label_i18n_path: 'statistics.users')
StatisticType.find_by!(key: 'project', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.projects')
StatisticType.find_by!(key: 'project', statistic_index_id: statistic_index_project.id).update!(label: nil, label_i18n_path: 'statistics.projects')
StatisticType.find_by!(key: 'revenue', statistic_index_id: statistic_index_user.id).update!(label: nil, label_i18n_path: 'statistics.revenue')
StatisticType.find_by!(key: 'revenue', statistic_index_id: statistic_index_user.id).update!(label: nil, label_i18n_path: 'statistics.revenue')
StatisticType.find_by!(key: 'booking', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.bookings')
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: 'booking', statistic_index_id: statistic_index_space.id).update!(label: nil, label_i18n_path: 'statistics.bookings')
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.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: 'paid-processed').update!(label: nil, label_i18n_path: 'statistics.paid-rocessed')
StatisticSubType.find_by!(key: 'aborted').update!(label: nil, label_i18n_path: 'statistics.aborted')
if StatisticSubType.count > 0
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: 'paid-processed').update!(label: nil, label_i18n_path: 'statistics.paid-rocessed')
StatisticSubType.find_by!(key: 'aborted').update!(label: nil, label_i18n_path: 'statistics.aborted')
end
end
end