From ce90bbf18630bfefc0c1bb0431ae8af4fae71783 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 3 Nov 2023 12:56:13 +0100 Subject: [PATCH] improvement: dynamic label (i18n) for stats structure tables --- .gitignore | 3 + CHANGELOG.md | 1 + app/models/concerns/label_i18n_concern.rb | 9 ++ app/models/statistic_field.rb | 2 + app/models/statistic_index.rb | 2 + app/models/statistic_sub_type.rb | 2 + app/models/statistic_type.rb | 2 + ...add_label_i18n_path_to_statistic_tables.rb | 99 +++++++++++++++++++ db/seeds/statistics.rb | 96 +++++++++--------- db/structure.sql | 52 +++++----- 10 files changed, 195 insertions(+), 73 deletions(-) create mode 100644 app/models/concerns/label_i18n_concern.rb create mode 100644 db/migrate/20231103093436_add_label_i18n_path_to_statistic_tables.rb diff --git a/.gitignore b/.gitignore index d5b342488..286270d43 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,6 @@ yarn-debug.log* /yarn-error.log yarn-debug.log* .yarn-integrity + +*.sql +*.tar.gz \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 62ca7656e..2517a79fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - adds a rake task to regenerate invoices by ids (see maintenance.rake) - Fix a bug: replaces custom ServerLocale middleware with sidekiq i18n middleware - adds a rake task to erase all reservations and invoices (fablab:maintenance:delete_all_reservations_and_invoices) +- improvement: dynamic label (i18n) for stats structure tables ## v6.2.0 2023 October 13 diff --git a/app/models/concerns/label_i18n_concern.rb b/app/models/concerns/label_i18n_concern.rb new file mode 100644 index 000000000..f1d80c11c --- /dev/null +++ b/app/models/concerns/label_i18n_concern.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module LabelI18nConcern + extend ActiveSupport::Concern + + def label + super.present? ? super : I18n.t(label_i18n_path) + end +end diff --git a/app/models/statistic_field.rb b/app/models/statistic_field.rb index 3daba6c21..fc3d204b0 100644 --- a/app/models/statistic_field.rb +++ b/app/models/statistic_field.rb @@ -1,3 +1,5 @@ class StatisticField < ApplicationRecord + include LabelI18nConcern + has_one :statistic_index end diff --git a/app/models/statistic_index.rb b/app/models/statistic_index.rb index 24b6ee0bf..8572e3e95 100644 --- a/app/models/statistic_index.rb +++ b/app/models/statistic_index.rb @@ -1,4 +1,6 @@ class StatisticIndex < ApplicationRecord + include LabelI18nConcern + has_many :statistic_types has_many :statistic_fields has_one :statistic_graph diff --git a/app/models/statistic_sub_type.rb b/app/models/statistic_sub_type.rb index c9317f5af..62da3aa87 100644 --- a/app/models/statistic_sub_type.rb +++ b/app/models/statistic_sub_type.rb @@ -1,4 +1,6 @@ class StatisticSubType < ApplicationRecord + include LabelI18nConcern + has_many :statistic_type_sub_types, dependent: :destroy has_many :statistic_types, through: :statistic_type_sub_types end diff --git a/app/models/statistic_type.rb b/app/models/statistic_type.rb index d0b44526d..c833730f2 100644 --- a/app/models/statistic_type.rb +++ b/app/models/statistic_type.rb @@ -3,6 +3,8 @@ # Allows splinting a StatisticIndex into multiple types. # e.g. The StatisticIndex "subscriptions" may have types like "1 month", "1 year", etc. class StatisticType < ApplicationRecord + include LabelI18nConcern + belongs_to :statistic_index has_many :statistic_type_sub_types, dependent: :destroy has_many :statistic_sub_types, through: :statistic_type_sub_types diff --git a/db/migrate/20231103093436_add_label_i18n_path_to_statistic_tables.rb b/db/migrate/20231103093436_add_label_i18n_path_to_statistic_tables.rb new file mode 100644 index 000000000..e5d392622 --- /dev/null +++ b/db/migrate/20231103093436_add_label_i18n_path_to_statistic_tables.rb @@ -0,0 +1,99 @@ +class AddLabelI18nPathToStatisticTables < ActiveRecord::Migration[7.0] + def change + add_column :statistic_indices, :label_i18n_path, :string + add_column :statistic_types, :label_i18n_path, :string + add_column :statistic_sub_types, :label_i18n_path, :string + add_column :statistic_fields, :label_i18n_path, :string + + # StatisticIndex + + statistic_index_subscription = StatisticIndex.find_by!(es_type_key: 'subscription') + statistic_index_subscription.update!(label: nil, label_i18n_path: 'statistics.subscriptions') + + statistic_index_machine = StatisticIndex.find_by!(es_type_key: 'machine') + statistic_index_machine.update!(label: nil, label_i18n_path: 'statistics.machines_hours') + + statistic_index_training = StatisticIndex.find_by!(es_type_key: 'training') + statistic_index_training.update!(label: nil, label_i18n_path: 'statistics.trainings') + + statistic_index_event = StatisticIndex.find_by!(es_type_key: 'event') + statistic_index_event.update!(label: nil, label_i18n_path: 'statistics.events') + + statistic_index_account = StatisticIndex.find_by!(es_type_key: 'account') + statistic_index_account.update!(label: nil, label_i18n_path: 'statistics.registrations') + + statistic_index_project = StatisticIndex.find_by!(es_type_key: 'project') + statistic_index_project.update!(label: nil, label_i18n_path: 'statistics.projects') + + statistic_index_user = StatisticIndex.find_by!(es_type_key: 'user') + statistic_index_user.update!(label: nil, label_i18n_path: 'statistics.users') + + statistic_index_space = StatisticIndex.find_by!(es_type_key: 'space') + statistic_index_space.update!(label: nil, label_i18n_path: 'statistics.spaces') + + statistic_index_order = StatisticIndex.find_by!(es_type_key: 'order') + statistic_index_order.update!(label: nil, label_i18n_path: 'statistics.orders') + + # StatisticField + + 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: '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: '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: '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: 'groupName', statistic_index_id: statistic_index_order.id).update!(label: nil, label_i18n_path: 'statistics.group') + + # 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') + + 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: '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: '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: 'store', statistic_index_id: statistic_index_order.id).update!(label: nil, label_i18n_path: 'statistics.store') + + # 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') + end +end diff --git a/db/seeds/statistics.rb b/db/seeds/statistics.rb index 5b7dd92af..5a33f7131 100644 --- a/db/seeds/statistics.rb +++ b/db/seeds/statistics.rb @@ -4,141 +4,141 @@ require_relative '../../lib/database/sequence' # statistic_indices unless StatisticIndex.find_by(es_type_key: 'subscription') - StatisticIndex.create!({ id: 1, es_type_key: 'subscription', label: I18n.t('statistics.subscriptions') }) + StatisticIndex.create!({ id: 1, es_type_key: 'subscription', label_i18n_path: 'statistics.subscriptions' }) end unless StatisticIndex.find_by(es_type_key: 'machine') - StatisticIndex.create!({ id: 2, es_type_key: 'machine', label: I18n.t('statistics.machines_hours') }) + StatisticIndex.create!({ id: 2, es_type_key: 'machine', label_i18n_path: 'statistics.machines_hours' }) end unless StatisticIndex.find_by(es_type_key: 'training') - StatisticIndex.create!({ id: 3, es_type_key: 'training', label: I18n.t('statistics.trainings') }) + StatisticIndex.create!({ id: 3, es_type_key: 'training', label_i18n_path: 'statistics.trainings' }) end -StatisticIndex.create!({ id: 4, es_type_key: 'event', label: I18n.t('statistics.events') }) unless StatisticIndex.find_by(es_type_key: 'event') +StatisticIndex.create!({ id: 4, es_type_key: 'event', label_i18n_path: 'statistics.events' }) unless StatisticIndex.find_by(es_type_key: 'event') unless StatisticIndex.find_by(es_type_key: 'account') - StatisticIndex.create!({ id: 5, es_type_key: 'account', label: I18n.t('statistics.registrations'), ca: false }) + StatisticIndex.create!({ id: 5, es_type_key: 'account', label_i18n_path: 'statistics.registrations', ca: false }) end unless StatisticIndex.find_by(es_type_key: 'project') - StatisticIndex.create!({ id: 6, es_type_key: 'project', label: I18n.t('statistics.projects'), ca: false }) + StatisticIndex.create!({ id: 6, es_type_key: 'project', label_i18n_path: 'statistics.projects', ca: false }) end unless StatisticIndex.find_by(es_type_key: 'user') - StatisticIndex.create!({ id: 7, es_type_key: 'user', label: I18n.t('statistics.users'), table: false, ca: false }) + StatisticIndex.create!({ id: 7, es_type_key: 'user', label_i18n_path: 'statistics.users', table: false, ca: false }) end Database::Sequence.update_id_seq(StatisticIndex.table_name) -StatisticIndex.create!({ es_type_key: 'space', label: I18n.t('statistics.spaces') }) unless StatisticIndex.find_by(es_type_key: 'space') -StatisticIndex.create!({ es_type_key: 'order', label: I18n.t('statistics.orders') }) unless StatisticIndex.find_by(es_type_key: 'order') +StatisticIndex.create!({ es_type_key: 'space', label_i18n_path: 'statistics.spaces' }) unless StatisticIndex.find_by(es_type_key: 'space') +StatisticIndex.create!({ es_type_key: 'order', label_i18n_path: 'statistics.orders' }) unless StatisticIndex.find_by(es_type_key: 'order') statistic_index_space = StatisticIndex.find_by(es_type_key: 'space') statistic_index_order = StatisticIndex.find_by(es_type_key: 'order') # statistic_fields unless StatisticField.find_by(key: 'spaceDates', statistic_index_id: statistic_index_space.id) - StatisticField.create!({ key: 'spaceDates', label: I18n.t('statistics.space_dates'), + StatisticField.create!({ key: 'spaceDates', label_i18n_path: 'statistics.space_dates', statistic_index_id: statistic_index_space.id, data_type: 'list' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: statistic_index_space.id) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: statistic_index_space.id, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: statistic_index_space.id, data_type: 'text' }) end unless StatisticField.find_by(key: 'machineDates', statistic_index_id: 2) - StatisticField.create!({ key: 'machineDates', label: I18n.t('statistics.machine_dates'), statistic_index_id: 2, data_type: 'list' }) + StatisticField.create!({ key: 'machineDates', label_i18n_path: 'statistics.machine_dates', statistic_index_id: 2, data_type: 'list' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: 2) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: 2, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 2, data_type: 'text' }) end unless StatisticField.find_by(key: 'trainingId', statistic_index_id: 3) - StatisticField.create!({ key: 'trainingId', label: I18n.t('statistics.training_id'), statistic_index_id: 3, data_type: 'index' }) + StatisticField.create!({ key: 'trainingId', label_i18n_path: 'statistics.training_id', statistic_index_id: 3, data_type: 'index' }) end unless StatisticField.find_by(key: 'trainingDate', statistic_index_id: 3) - StatisticField.create!({ key: 'trainingDate', label: I18n.t('statistics.training_date'), statistic_index_id: 3, data_type: 'date' }) + StatisticField.create!({ key: 'trainingDate', label_i18n_path: 'statistics.training_date', statistic_index_id: 3, data_type: 'date' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: 3) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: 3, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 3, data_type: 'text' }) end unless StatisticField.find_by(key: 'eventId', statistic_index_id: 4) - StatisticField.create!({ key: 'eventId', label: I18n.t('statistics.event_id'), statistic_index_id: 4, data_type: 'index' }) + StatisticField.create!({ key: 'eventId', label_i18n_path: 'statistics.event_id', statistic_index_id: 4, data_type: 'index' }) end unless StatisticField.find_by(key: 'eventDate', statistic_index_id: 4) - StatisticField.create!({ key: 'eventDate', label: I18n.t('statistics.event_date'), statistic_index_id: 4, data_type: 'date' }) + StatisticField.create!({ key: 'eventDate', label_i18n_path: 'statistics.event_date', statistic_index_id: 4, data_type: 'date' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: 4) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: 4, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 4, data_type: 'text' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: 5) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: 5, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 5, data_type: 'text' }) end unless StatisticField.find_by(key: 'themes', statistic_index_id: 6) - StatisticField.create!({ key: 'themes', label: I18n.t('statistics.themes'), statistic_index_id: 6, data_type: 'list' }) + StatisticField.create!({ key: 'themes', label_i18n_path: 'statistics.themes', statistic_index_id: 6, data_type: 'list' }) end unless StatisticField.find_by(key: 'components', statistic_index_id: 6) - StatisticField.create!({ key: 'components', label: I18n.t('statistics.components'), statistic_index_id: 6, data_type: 'list' }) + StatisticField.create!({ key: 'components', label_i18n_path: 'statistics.components', statistic_index_id: 6, data_type: 'list' }) end unless StatisticField.find_by(key: 'machines', statistic_index_id: 6) - StatisticField.create!({ key: 'machines', label: I18n.t('statistics.machines'), statistic_index_id: 6, data_type: 'list' }) + StatisticField.create!({ key: 'machines', label_i18n_path: 'statistics.machines', statistic_index_id: 6, data_type: 'list' }) end unless StatisticField.find_by(key: 'status', statistic_index_id: 6) - StatisticField.create!({ key: 'status', label: I18n.t('statistics.project_status'), statistic_index_id: 6, data_type: 'text' }) + StatisticField.create!({ key: 'status', label_i18n_path: 'statistics.project_status', statistic_index_id: 6, data_type: 'text' }) end unless StatisticField.find_by(key: 'name', statistic_index_id: 6) - StatisticField.create!({ key: 'name', label: I18n.t('statistics.project_name'), statistic_index_id: 6, data_type: 'text' }) + StatisticField.create!({ key: 'name', label_i18n_path: 'statistics.project_name', statistic_index_id: 6, data_type: 'text' }) end unless StatisticField.find_by(key: 'projectUserNames', statistic_index_id: 6) - StatisticField.create!({ key: 'projectUserNames', label: I18n.t('statistics.project_user_names'), statistic_index_id: 6, data_type: 'list' }) + StatisticField.create!({ key: 'projectUserNames', label_i18n_path: 'statistics.project_user_names', statistic_index_id: 6, data_type: 'list' }) end unless StatisticField.find_by(key: 'name', statistic_index_id: 4) - StatisticField.create!({ key: 'name', label: I18n.t('statistics.event_name'), statistic_index_id: 4, data_type: 'text' }) + StatisticField.create!({ key: 'name', label_i18n_path: 'statistics.event_name', statistic_index_id: 4, data_type: 'text' }) end unless StatisticField.find_by(key: 'userId', statistic_index_id: 7) - StatisticField.create!({ key: 'userId', label: I18n.t('statistics.user_id'), statistic_index_id: 7, data_type: 'index' }) + StatisticField.create!({ key: 'userId', label_i18n_path: 'statistics.user_id', statistic_index_id: 7, data_type: 'index' }) end unless StatisticField.find_by(key: 'eventTheme', statistic_index_id: 4) - StatisticField.create!({ key: 'eventTheme', label: I18n.t('statistics.event_theme'), statistic_index_id: 4, data_type: 'text' }) + StatisticField.create!({ key: 'eventTheme', label_i18n_path: 'statistics.event_theme', statistic_index_id: 4, data_type: 'text' }) end unless StatisticField.find_by(key: 'ageRange', statistic_index_id: 4) - StatisticField.create!({ key: 'ageRange', label: I18n.t('statistics.age_range'), statistic_index_id: 4, data_type: 'text' }) + StatisticField.create!({ key: 'ageRange', label_i18n_path: 'statistics.age_range', statistic_index_id: 4, data_type: 'text' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: 1) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: 1, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 1, data_type: 'text' }) end unless StatisticField.find_by(key: 'groupName', statistic_index_id: statistic_index_order.id) - StatisticField.create!({ key: 'groupName', label: I18n.t('statistics.group'), statistic_index_id: statistic_index_order.id, data_type: 'text' }) + StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: statistic_index_order.id, data_type: 'text' }) end # statistic_types unless StatisticType.find_by(key: 'booking', statistic_index_id: 2) - StatisticType.create!({ statistic_index_id: 2, key: 'booking', label: I18n.t('statistics.bookings'), graph: true, simple: true }) + StatisticType.create!({ statistic_index_id: 2, key: 'booking', label_i18n_path: 'statistics.bookings', graph: true, simple: true }) end unless StatisticType.find_by(key: 'hour', statistic_index_id: 2) - StatisticType.create!({ statistic_index_id: 2, key: 'hour', label: I18n.t('statistics.hours_number'), graph: true, simple: false }) + StatisticType.create!({ statistic_index_id: 2, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: true, simple: false }) end unless StatisticType.find_by(key: 'booking', statistic_index_id: 3) - StatisticType.create!({ statistic_index_id: 3, key: 'booking', label: I18n.t('statistics.bookings'), graph: false, simple: true }) + StatisticType.create!({ statistic_index_id: 3, key: 'booking', label_i18n_path: 'statistics.bookings', graph: false, simple: true }) end unless StatisticType.find_by(key: 'hour', statistic_index_id: 3) - StatisticType.create!({ statistic_index_id: 3, key: 'hour', label: I18n.t('statistics.hours_number'), graph: false, simple: false }) + StatisticType.create!({ statistic_index_id: 3, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: false, simple: false }) end unless StatisticType.find_by(key: 'booking', statistic_index_id: 4) - StatisticType.create!({ statistic_index_id: 4, key: 'booking', label: I18n.t('statistics.tickets_number'), graph: false, simple: false }) + StatisticType.create!({ statistic_index_id: 4, key: 'booking', label_i18n_path: 'statistics.tickets_number', graph: false, simple: false }) end unless StatisticType.find_by(key: 'hour', statistic_index_id: 4) - StatisticType.create!({ statistic_index_id: 4, key: 'hour', label: I18n.t('statistics.hours_number'), graph: false, simple: false }) + StatisticType.create!({ statistic_index_id: 4, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: false, simple: false }) end unless StatisticType.find_by(key: 'member', statistic_index_id: 5) - StatisticType.create!({ statistic_index_id: 5, key: 'member', label: I18n.t('statistics.users'), graph: true, simple: true }) + StatisticType.create!({ statistic_index_id: 5, key: 'member', label_i18n_path: 'statistics.users', graph: true, simple: true }) end unless StatisticType.find_by(key: 'project', statistic_index_id: 6) - StatisticType.create!({ statistic_index_id: 6, key: 'project', label: I18n.t('statistics.projects'), graph: false, simple: true }) + StatisticType.create!({ statistic_index_id: 6, key: 'project', label_i18n_path: 'statistics.projects', graph: false, simple: true }) end unless StatisticType.find_by(key: 'revenue', statistic_index_id: 7) - StatisticType.create!({ statistic_index_id: 7, key: 'revenue', label: I18n.t('statistics.revenue'), graph: false, simple: false }) + StatisticType.create!({ statistic_index_id: 7, key: 'revenue', label_i18n_path: 'statistics.revenue', graph: false, simple: false }) end unless StatisticType.find_by(key: 'booking', statistic_index_id: statistic_index_space.id) - StatisticType.create!({ statistic_index_id: statistic_index_space.id, key: 'booking', label: I18n.t('statistics.bookings'), + StatisticType.create!({ statistic_index_id: statistic_index_space.id, key: 'booking', label_i18n_path: 'statistics.bookings', graph: true, simple: true }) end unless StatisticType.find_by(key: 'hour', statistic_index_id: statistic_index_space.id) - StatisticType.create!({ statistic_index_id: statistic_index_space.id, key: 'hour', label: I18n.t('statistics.hours_number'), + StatisticType.create!({ statistic_index_id: statistic_index_space.id, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: true, simple: false }) end unless StatisticType.find_by(key: 'store', statistic_index_id: statistic_index_order.id) - StatisticType.create!({ statistic_index_id: statistic_index_order.id, key: 'store', label: I18n.t('statistics.store'), + StatisticType.create!({ statistic_index_id: statistic_index_order.id, key: 'store', label_i18n_path: 'statistics.store', graph: true, simple: true }) end Plan.find_each do |plan| @@ -155,19 +155,19 @@ end # statistic_sub_types unless StatisticSubType.find_by(key: 'created') - StatisticSubType.create!({ key: 'created', label: I18n.t('statistics.account_creation'), + StatisticSubType.create!({ key: 'created', label_i18n_path: 'statistics.account_creation', statistic_types: StatisticIndex.find_by(es_type_key: 'account').statistic_types }) end unless StatisticSubType.find_by(key: 'published') - StatisticSubType.create!({ key: 'published', label: I18n.t('statistics.project_publication'), + StatisticSubType.create!({ key: 'published', label_i18n_path: 'statistics.project_publication', statistic_types: StatisticIndex.find_by(es_type_key: 'project').statistic_types }) end unless StatisticSubType.find_by(key: 'paid-processed') - StatisticSubType.create!({ key: 'paid-processed', label: I18n.t('statistics.paid-processed'), + StatisticSubType.create!({ key: 'paid-processed', label_i18n_path: 'statistics.paid-rocessed', statistic_types: statistic_index_order.statistic_types }) end unless StatisticSubType.find_by(key: 'aborted') - StatisticSubType.create!({ key: 'aborted', label: I18n.t('statistics.aborted'), statistic_types: statistic_index_order.statistic_types }) + StatisticSubType.create!({ key: 'aborted', label_i18n_path: 'statistics.aborted', statistic_types: statistic_index_order.statistic_types }) end Plan.find_each do |plan| type = plan.find_statistic_type diff --git a/db/structure.sql b/db/structure.sql index 417fb72d7..cda265f42 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -108,8 +108,8 @@ SET default_tablespace = ''; CREATE TABLE public.abuses ( id integer NOT NULL, - signaled_id integer, signaled_type character varying, + signaled_id integer, first_name character varying, last_name character varying, email character varying, @@ -229,8 +229,8 @@ CREATE TABLE public.addresses ( locality character varying, country character varying, postal_code character varying, - placeable_id integer, placeable_type character varying, + placeable_id integer, created_at timestamp without time zone, updated_at timestamp without time zone ); @@ -339,8 +339,8 @@ CREATE TABLE public.ar_internal_metadata ( CREATE TABLE public.assets ( id integer NOT NULL, - viewable_id integer, viewable_type character varying, + viewable_id integer, attachment character varying, type character varying, created_at timestamp without time zone, @@ -1066,8 +1066,8 @@ ALTER SEQUENCE public.coupons_id_seq OWNED BY public.coupons.id; CREATE TABLE public.credits ( id integer NOT NULL, - creditable_id integer, creditable_type character varying, + creditable_id integer, plan_id integer, hours integer, created_at timestamp without time zone, @@ -1868,15 +1868,15 @@ ALTER SEQUENCE public.notification_types_id_seq OWNED BY public.notification_typ CREATE TABLE public.notifications ( id integer NOT NULL, receiver_id integer, - attached_object_id integer, attached_object_type character varying, + attached_object_id integer, notification_type_id integer, is_read boolean DEFAULT false, created_at timestamp without time zone, updated_at timestamp without time zone, receiver_type character varying, is_send boolean DEFAULT false, - meta_data jsonb DEFAULT '{}'::jsonb + meta_data jsonb DEFAULT '"{}"'::jsonb ); @@ -2605,8 +2605,8 @@ CREATE TABLE public.prices ( id integer NOT NULL, group_id integer, plan_id integer, - priceable_id integer, priceable_type character varying, + priceable_id integer, amount integer, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, @@ -3164,8 +3164,8 @@ CREATE TABLE public.reservations ( message text, created_at timestamp without time zone, updated_at timestamp without time zone, - reservable_id integer, reservable_type character varying, + reservable_id integer, nb_reserve_places integer, statistic_profile_id integer, reservation_context_id bigint @@ -3198,8 +3198,8 @@ ALTER SEQUENCE public.reservations_id_seq OWNED BY public.reservations.id; CREATE TABLE public.roles ( id integer NOT NULL, name character varying, - resource_id integer, resource_type character varying, + resource_id integer, created_at timestamp without time zone, updated_at timestamp without time zone ); @@ -3451,7 +3451,8 @@ CREATE TABLE public.statistic_fields ( label character varying, created_at timestamp without time zone, updated_at timestamp without time zone, - data_type character varying + data_type character varying, + label_i18n_path character varying ); @@ -3518,7 +3519,8 @@ CREATE TABLE public.statistic_indices ( created_at timestamp without time zone, updated_at timestamp without time zone, "table" boolean DEFAULT true, - ca boolean DEFAULT true + ca boolean DEFAULT true, + label_i18n_path character varying ); @@ -3651,7 +3653,8 @@ CREATE TABLE public.statistic_sub_types ( key character varying, label character varying, created_at timestamp without time zone, - updated_at timestamp without time zone + updated_at timestamp without time zone, + label_i18n_path character varying ); @@ -3718,7 +3721,8 @@ CREATE TABLE public.statistic_types ( graph boolean, created_at timestamp without time zone, updated_at timestamp without time zone, - simple boolean + simple boolean, + label_i18n_path character varying ); @@ -6019,6 +6023,14 @@ ALTER TABLE ONLY public.roles ADD CONSTRAINT roles_pkey PRIMARY KEY (id); +-- +-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.schema_migrations + ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); + + -- -- Name: settings settings_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -7783,13 +7795,6 @@ CREATE INDEX proof_of_identity_type_id_and_proof_of_identity_refusal_id ON publi CREATE UNIQUE INDEX unique_not_null_external_id ON public.invoicing_profiles USING btree (external_id) WHERE (external_id IS NOT NULL); --- --- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING btree (version); - - -- -- Name: accounting_periods accounting_periods_del_protect; Type: RULE; Schema: public; Owner: - -- @@ -8854,7 +8859,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20140605125131'), ('20140605142133'), ('20140605151442'), -('20140606133116'), ('20140609092700'), ('20140609092827'), ('20140610153123'), @@ -8923,14 +8927,12 @@ INSERT INTO "schema_migrations" (version) VALUES ('20150507075620'), ('20150512123546'), ('20150520132030'), -('20150520133409'), ('20150526130729'), ('20150527153312'), ('20150529113555'), ('20150601125944'), ('20150603104502'), ('20150603104658'), -('20150603133050'), ('20150604081757'), ('20150604131525'), ('20150608142234'), @@ -9012,7 +9014,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20160905142700'), ('20160906094739'), ('20160906094847'), -('20160906145713'), ('20160915105234'), ('20161123104604'), ('20170109085345'), @@ -9201,6 +9202,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230828073428'), ('20230831103208'), ('20230901090637'), -('20230907124230'); +('20230907124230'), +('20231103093436');