From f58048ee68e5a9b1aa9bc552f463ab2c90286d78 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Sun, 19 May 2024 12:33:27 +0200 Subject: [PATCH 1/3] We postgres now --- Gemfile | 2 +- Gemfile.lock | 4 ++-- config/database.yml | 13 ++++++------- docker-compose.prod.yml | 22 ++++++++++------------ docker-compose.yml | 36 ++++++++++++++++-------------------- 5 files changed, 35 insertions(+), 42 deletions(-) diff --git a/Gemfile b/Gemfile index cf119cc1..45530c42 100644 --- a/Gemfile +++ b/Gemfile @@ -110,7 +110,7 @@ gem 'simple_enum' gem 'record_tag_helper' # Database -gem 'mysql2' +gem 'pg' group :development do gem 'rails-erd' diff --git a/Gemfile.lock b/Gemfile.lock index 6bf850ee..b61c515c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -197,7 +197,6 @@ GEM multi_xml (0.7.1) bigdecimal (~> 3.1) mutex_m (0.2.0) - mysql2 (0.5.6) net-http (0.4.1) uri net-imap (0.4.11) @@ -251,6 +250,7 @@ GEM parser (3.3.1.0) ast (~> 2.4.1) racc + pg (1.5.6) poltergeist (1.18.1) capybara (>= 2.1, < 4) cliver (~> 0.3.1) @@ -495,10 +495,10 @@ DEPENDENCIES letter_opener listen minitest (= 5.15.0) - mysql2 omniauth-rails_csrf_protection omniauth-zeuswpi paper_trail + pg poltergeist puma rails (~> 6.1) diff --git a/config/database.yml b/config/database.yml index 48e222fd..697b91ed 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,21 +1,20 @@ default: &default - adapter: mysql2 + adapter: postgresql pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> host: 127.0.0.1 - port: 3306 - database: gandalf - username: gandalf + username: postgres password: password - encoding: utf8mb4 - collation: utf8mb4_unicode_ci + encoding: utf8 + port: 5432 development: <<: *default + database: gandalf test: <<: *default database: gandalf-test - port: 3307 + port: 5433 production: <<: *default diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 5dd5b027..f3d533cc 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -2,17 +2,15 @@ version: '3.3' services: db: - image: mariadb:10.8 - volumes: - - db_data:/var/lib/mysql - command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci'] + image: postgres:16 environment: - MYSQL_ROOT_PASSWORD: strong-password - MYSQL_DATABASE: gandalf - MYSQL_USER: gandalf - MYSQL_PASSWORD: password + POSTGRES_DB: gandalf + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + volumes: + - gandalf_data:/var/lib/postgresql/data ports: - - "3306:3306" + - "5432:5432" web: build: . @@ -23,7 +21,7 @@ services: volumes: - storage:/app/storage environment: - DATABASE_URL: mysql2://gandalf:password@db/gandalf + DATABASE_URL: postgresql://postgres:password@db/gandalf RAILS_LOG_TO_STDOUT: 1 SECRET_AUTH_USERNAME: admin SECRET_AUTH_PASSWORD: admin-password @@ -37,7 +35,7 @@ services: volumes: - storage:/app/storage environment: - DATABASE_URL: mysql2://gandalf:password@db/gandalf + DATABASE_URL: postgresql://postgres:password@db/gandalf REDIS_URL: redis://redis:6379 entrypoint: bundle exec sidekiq @@ -49,6 +47,6 @@ services: - "6379:6379" volumes: - db_data: + gandalf_data: redis_data: storage: diff --git a/docker-compose.yml b/docker-compose.yml index b1a6c3e0..0e82e694 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,30 +2,26 @@ version: '3.3' services: db: - image: mariadb:10.8 - volumes: - - db_data:/var/lib/mysql - command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci'] + image: postgres:16 environment: - MYSQL_ROOT_PASSWORD: strong-password - MYSQL_DATABASE: gandalf - MYSQL_USER: gandalf - MYSQL_PASSWORD: password + POSTGRES_DB: gandalf + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + volumes: + - gandalf_data:/var/lib/postgresql/data ports: - - "3306:3306" + - "5432:5432" db-test: - image: mariadb:10.8 - volumes: - - db-test_data:/var/lib/mysql - command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci'] + image: postgres:16 environment: - MYSQL_ROOT_PASSWORD: strong-password - MYSQL_DATABASE: gandalf-test - MYSQL_USER: gandalf - MYSQL_PASSWORD: password + POSTGRES_DB: gandalf-test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + volumes: + - gandalf_test_data:/var/lib/postgresql/data ports: - - "3307:3306" + - "5433:5432" redis: image: redis:7-alpine @@ -35,6 +31,6 @@ services: - "6379:6379" volumes: - db_data: - db-test_data: + gandalf_data: + gandalf_test_data: redis_data: From 6cdc3389fb083cd581e3d495da4db243a6014559 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Sun, 19 May 2024 13:34:34 +0200 Subject: [PATCH 2/3] Convert and annotate --- app/actions/user/fetch_enrolled_clubs.rb | 2 +- app/controllers/events_controller.rb | 4 ++-- app/controllers/registrations_controller.rb | 2 +- app/models/access_level.rb | 12 +++++----- app/models/club.rb | 4 ++-- app/models/clubs_user.rb | 12 +++++----- app/models/enrolled_clubs_member.rb | 14 +++++------ app/models/event.rb | 14 +++++------ app/models/partner.rb | 20 ++++++++-------- app/models/registration.rb | 24 +++++++++---------- app/models/user.rb | 14 +++++------ .../20140121123250_add_casfields_to_users.rb | 2 +- db/schema.rb | 2 +- docker-compose.yml | 1 + test/fixtures/access_levels.yml | 12 +++++----- test/fixtures/clubs.yml | 4 ++-- test/fixtures/events.yml | 14 +++++------ test/fixtures/partners.yml | 20 ++++++++-------- test/fixtures/registrations.yml | 24 +++++++++---------- test/fixtures/users.yml | 10 ++++---- test/models/access_level_test.rb | 12 +++++----- test/models/club_test.rb | 4 ++-- test/models/event_test.rb | 14 +++++------ test/models/partner_test.rb | 20 ++++++++-------- test/models/registration_test.rb | 24 +++++++++---------- test/models/user_test.rb | 8 +++---- 26 files changed, 147 insertions(+), 146 deletions(-) diff --git a/app/actions/user/fetch_enrolled_clubs.rb b/app/actions/user/fetch_enrolled_clubs.rb index c5282983..480a3820 100644 --- a/app/actions/user/fetch_enrolled_clubs.rb +++ b/app/actions/user/fetch_enrolled_clubs.rb @@ -10,7 +10,7 @@ def initialize(user) def call resp = HTTParty.get("http://registratie.fkgent.be/api/v2/members/clubs_for_ugent_nr.json", query: - { key: Rails.application.secrets.enrollment_key, ugent_nr: user.cas_ugentStudentID }) + { key: Rails.application.secrets.enrollment_key, ugent_nr: user.cas_ugentstudentid }) return unless resp.code == 200 diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index be404756..0d6a0cab 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -22,7 +22,7 @@ def show return unless current_user @registration.name = current_user.display_name - @registration.student_number = current_user.cas_ugentStudentID + @registration.student_number = current_user.cas_ugentstudentid @registration.email = current_user.cas_mail respond_to do |format| @@ -84,7 +84,7 @@ def statistics @data = @event.access_levels.map do |al| { name: al.name, - data: zeros.merge(al.registrations.group('date(registrations.created_at)').count.transform_keys { |key| key.strftime("%Y-%m-%d") }) + data: zeros.merge(al.registrations.group('registrations.name, date(registrations.created_at)').count.transform_keys { |key| key.strftime("%Y-%m-%d") }) } end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 7b5e6599..74e9d6d7 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -49,7 +49,7 @@ def create @registration.paid = 0 # overwrite student_number so setting this will not work - @registration.student_number = current_user.cas_ugentStudentID if requested_access_level.requires_login? + @registration.student_number = current_user.cas_ugentstudentid if requested_access_level.requires_login? # Send the confirmation email. if @registration.save diff --git a/app/models/access_level.rb b/app/models/access_level.rb index 0e9cbc90..35a06cfb 100644 --- a/app/models/access_level.rb +++ b/app/models/access_level.rb @@ -55,22 +55,22 @@ def price=(value) # # Table name: access_levels # -# id :integer not null, primary key -# capacity :integer +# id :bigint not null, primary key +# capacity :bigint # has_comment :boolean # hidden :boolean # name :string(255) # permit :string(255) default("everyone") -# price :integer +# price :bigint # created_at :datetime # updated_at :datetime -# event_id :integer +# event_id :bigint # # Indexes # -# index_access_levels_on_event_id (event_id) +# idx_16847_index_access_levels_on_event_id (event_id) # # Foreign Keys # -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/app/models/club.rb b/app/models/club.rb index 9858518d..1f2a46a5 100644 --- a/app/models/club.rb +++ b/app/models/club.rb @@ -22,7 +22,7 @@ def name # # Table name: clubs # -# id :integer not null, primary key +# id :bigint not null, primary key # display_name :string(255) # full_name :string(255) # internal_name :string(255) @@ -31,5 +31,5 @@ def name # # Indexes # -# index_clubs_on_internal_name (internal_name) UNIQUE +# idx_16882_index_clubs_on_internal_name (internal_name) UNIQUE # diff --git a/app/models/clubs_user.rb b/app/models/clubs_user.rb index 828dcfe8..98685032 100644 --- a/app/models/clubs_user.rb +++ b/app/models/clubs_user.rb @@ -9,16 +9,16 @@ class ClubsUser < ApplicationRecord # # Table name: clubs_users # -# club_id :integer -# user_id :integer +# club_id :bigint +# user_id :bigint # # Indexes # -# fk_rails_b7c6964840 (user_id) -# index_clubs_users_on_club_id_and_user_id (club_id,user_id) UNIQUE +# idx_16891_fk_rails_b7c6964840 (user_id) +# idx_16891_index_clubs_users_on_club_id_and_user_id (club_id,user_id) UNIQUE # # Foreign Keys # -# fk_rails_... (club_id => clubs.id) ON DELETE => cascade -# fk_rails_... (user_id => users.id) ON DELETE => cascade +# fk_rails_... (club_id => clubs.id) ON DELETE => cascade ON UPDATE => restrict +# fk_rails_... (user_id => users.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/app/models/enrolled_clubs_member.rb b/app/models/enrolled_clubs_member.rb index cfcd8e8a..61ea795a 100644 --- a/app/models/enrolled_clubs_member.rb +++ b/app/models/enrolled_clubs_member.rb @@ -9,17 +9,17 @@ class EnrolledClubsMember < ApplicationRecord # # Table name: enrolled_clubs_members # -# club_id :integer not null -# user_id :integer not null +# club_id :bigint not null +# user_id :bigint not null # # Indexes # -# index_enrolled_clubs_members_on_club_id (club_id) -# index_enrolled_clubs_members_on_club_id_and_user_id (club_id,user_id) UNIQUE -# index_enrolled_clubs_members_on_user_id (user_id) +# idx_16894_index_enrolled_clubs_members_on_club_id (club_id) +# idx_16894_index_enrolled_clubs_members_on_club_id_and_user_id (club_id,user_id) UNIQUE +# idx_16894_index_enrolled_clubs_members_on_user_id (user_id) # # Foreign Keys # -# fk_rails_... (club_id => clubs.id) ON DELETE => cascade -# fk_rails_... (user_id => users.id) ON DELETE => cascade +# fk_rails_... (club_id => clubs.id) ON DELETE => cascade ON UPDATE => restrict +# fk_rails_... (user_id => users.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/app/models/event.rb b/app/models/event.rb index 58bfb3e1..2cb1d0ac 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -38,14 +38,14 @@ def toggle_registration_open # # Table name: events # -# id :integer not null, primary key +# id :bigint not null, primary key # bank_number :string(255) # contact_email :string(255) -# description :text(16777215) +# description :text # end_date :datetime # export_content_type :string(255) # export_file_name :string(255) -# export_file_size :integer +# export_file_size :bigint # export_status :string(255) # export_updated_at :datetime # location :string(255) @@ -56,18 +56,18 @@ def toggle_registration_open # require_physical_ticket :boolean default(FALSE), not null # show_statistics :boolean # show_ticket_count :boolean default(TRUE) -# signature :text(65535) +# signature :text # start_date :datetime # website :string(255) # created_at :datetime # updated_at :datetime -# club_id :integer +# club_id :bigint # # Indexes # -# fk_rails_fc45ac705d (club_id) +# idx_16898_fk_rails_fc45ac705d (club_id) # # Foreign Keys # -# fk_rails_... (club_id => clubs.id) ON DELETE => cascade +# fk_rails_... (club_id => clubs.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/app/models/partner.rb b/app/models/partner.rb index bb91064a..88426473 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -32,7 +32,7 @@ def deliver # # Table name: partners # -# id :integer not null, primary key +# id :bigint not null, primary key # authentication_token :string(255) # confirmed :boolean # current_sign_in_at :datetime @@ -44,21 +44,21 @@ def deliver # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string(255) -# sign_in_count :integer default(0), not null +# sign_in_count :bigint default(0), not null # created_at :datetime # updated_at :datetime -# access_level_id :integer -# event_id :integer +# access_level_id :bigint +# event_id :bigint # # Indexes # -# fk_rails_188986c214 (event_id) -# index_partners_on_access_level_id (access_level_id) -# index_partners_on_authentication_token (authentication_token) -# index_partners_on_reset_password_token (reset_password_token) UNIQUE +# idx_16916_fk_rails_188986c214 (event_id) +# idx_16916_index_partners_on_access_level_id (access_level_id) +# idx_16916_index_partners_on_authentication_token (authentication_token) +# idx_16916_index_partners_on_reset_password_token (reset_password_token) UNIQUE # # Foreign Keys # -# fk_rails_... (access_level_id => access_levels.id) -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (access_level_id => access_levels.id) ON DELETE => restrict ON UPDATE => restrict +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/app/models/registration.rb b/app/models/registration.rb index dea16531..3dfbcdee 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -134,32 +134,32 @@ def to_cents(value) # # Table name: registrations # -# id :integer not null, primary key +# id :bigint not null, primary key # barcode :string(255) # barcode_data :string(255) # checked_in_at :datetime -# comment :text(65535) +# comment :text # email :string(255) # name :string(255) -# paid :integer +# paid :bigint # payment_code :string(255) -# price :integer +# price :bigint # student_number :string(255) # token :string(255) not null # created_at :datetime # updated_at :datetime -# access_level_id :integer not null -# event_id :integer +# access_level_id :bigint not null +# event_id :bigint # # Indexes # -# index_registrations_on_access_level_id (access_level_id) -# index_registrations_on_event_id (event_id) -# index_registrations_on_payment_code (payment_code) UNIQUE -# index_registrations_on_token (token) +# idx_16930_index_registrations_on_access_level_id (access_level_id) +# idx_16930_index_registrations_on_event_id (event_id) +# idx_16930_index_registrations_on_payment_code (payment_code) UNIQUE +# idx_16930_index_registrations_on_token (token) # # Foreign Keys # -# fk_rails_... (access_level_id => access_levels.id) -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (access_level_id => access_levels.id) ON DELETE => restrict ON UPDATE => restrict +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/app/models/user.rb b/app/models/user.rb index 5dedcde3..c5ff724d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,7 +16,7 @@ class User < ApplicationRecord after_create :enqueue_fetch_club, :enqueue_fetch_enrolled_clubs # this should add all extra CAS attributes returned by the server to the current session - # extra var in session: cas_givenname, cas_surname, cas_ugentStudentID, cas_mail, cas_uid (= UGent login) + # extra var in session: cas_givenname, cas_surname, cas_ugentstudentid, cas_mail, cas_uid (= UGent login) def cas_extra_attributes=(extra_attributes) extra_attributes.each do |name, value| # I prefer a case over reflection; this is safer if we suddenly get an @@ -27,7 +27,7 @@ def cas_extra_attributes=(extra_attributes) when :surname self.cas_surname = value when :ugentStudentID - self.cas_ugentStudentID = value + self.cas_ugentstudentid = value when :mail self.cas_mail = value when :uid @@ -37,7 +37,7 @@ def cas_extra_attributes=(extra_attributes) self.save! - if self.cas_ugentStudentID # rubocop:disable Style/GuardClause + if self.cas_ugentstudentid # rubocop:disable Style/GuardClause enqueue_fetch_club enqueue_fetch_enrolled_clubs end @@ -79,24 +79,24 @@ def self.from_omniauth(auth) # # Table name: users # -# id :integer not null, primary key +# id :bigint not null, primary key # admin :boolean # cas_givenname :string(255) # cas_mail :string(255) # cas_surname :string(255) -# cas_ugentStudentID :string(255) +# cas_ugentstudentid :string(255) # cas_uid :string(255) # current_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_at :datetime # last_sign_in_ip :string(255) # remember_created_at :datetime -# sign_in_count :integer default(0), not null +# sign_in_count :bigint default(0), not null # username :string(255) not null # created_at :datetime # updated_at :datetime # # Indexes # -# index_users_on_username (username) UNIQUE +# idx_16946_index_users_on_username (username) UNIQUE # diff --git a/db/migrate/20140121123250_add_casfields_to_users.rb b/db/migrate/20140121123250_add_casfields_to_users.rb index 3de7ee52..6b76e3b7 100644 --- a/db/migrate/20140121123250_add_casfields_to_users.rb +++ b/db/migrate/20140121123250_add_casfields_to_users.rb @@ -2,7 +2,7 @@ class AddCasfieldsToUsers < ActiveRecord::Migration[4.2] def change add_column :users, :cas_givenname, :string add_column :users, :cas_surname, :string - add_column :users, :cas_ugentStudentID, :string + add_column :users, :cas_ugentstudentid, :string add_column :users, :cas_mail, :string add_column :users, :cas_uid, :string end diff --git a/db/schema.rb b/db/schema.rb index 5b3def57..19809816 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -161,7 +161,7 @@ t.datetime "updated_at" t.string "cas_givenname" t.string "cas_surname" - t.string "cas_ugentStudentID" + t.string "cas_ugentstudentid" t.string "cas_mail" t.string "cas_uid" t.boolean "admin" diff --git a/docker-compose.yml b/docker-compose.yml index 0e82e694..00859585 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,6 +31,7 @@ services: - "6379:6379" volumes: + db_data: gandalf_data: gandalf_test_data: redis_data: diff --git a/test/fixtures/access_levels.yml b/test/fixtures/access_levels.yml index 8bbf97ed..10fc8ad9 100644 --- a/test/fixtures/access_levels.yml +++ b/test/fixtures/access_levels.yml @@ -68,22 +68,22 @@ students_only: # # Table name: access_levels # -# id :integer not null, primary key -# capacity :integer +# id :bigint not null, primary key +# capacity :bigint # has_comment :boolean # hidden :boolean # name :string(255) # permit :string(255) default("everyone") -# price :integer +# price :bigint # created_at :datetime # updated_at :datetime -# event_id :integer +# event_id :bigint # # Indexes # -# index_access_levels_on_event_id (event_id) +# idx_16847_index_access_levels_on_event_id (event_id) # # Foreign Keys # -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/fixtures/clubs.yml b/test/fixtures/clubs.yml index ed416de3..6199d99a 100644 --- a/test/fixtures/clubs.yml +++ b/test/fixtures/clubs.yml @@ -16,7 +16,7 @@ fk: # # Table name: clubs # -# id :integer not null, primary key +# id :bigint not null, primary key # display_name :string(255) # full_name :string(255) # internal_name :string(255) @@ -25,5 +25,5 @@ fk: # # Indexes # -# index_clubs_on_internal_name (internal_name) UNIQUE +# idx_16882_index_clubs_on_internal_name (internal_name) UNIQUE # diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml index 3c53eedc..6a5cfce4 100644 --- a/test/fixtures/events.yml +++ b/test/fixtures/events.yml @@ -49,14 +49,14 @@ sko: # # Table name: events # -# id :integer not null, primary key +# id :bigint not null, primary key # bank_number :string(255) # contact_email :string(255) -# description :text(16777215) +# description :text # end_date :datetime # export_content_type :string(255) # export_file_name :string(255) -# export_file_size :integer +# export_file_size :bigint # export_status :string(255) # export_updated_at :datetime # location :string(255) @@ -67,18 +67,18 @@ sko: # require_physical_ticket :boolean default(FALSE), not null # show_statistics :boolean # show_ticket_count :boolean default(TRUE) -# signature :text(65535) +# signature :text # start_date :datetime # website :string(255) # created_at :datetime # updated_at :datetime -# club_id :integer +# club_id :bigint # # Indexes # -# fk_rails_fc45ac705d (club_id) +# idx_16898_fk_rails_fc45ac705d (club_id) # # Foreign Keys # -# fk_rails_... (club_id => clubs.id) ON DELETE => cascade +# fk_rails_... (club_id => clubs.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/fixtures/partners.yml b/test/fixtures/partners.yml index 4bf3ed33..9693107d 100644 --- a/test/fixtures/partners.yml +++ b/test/fixtures/partners.yml @@ -28,7 +28,7 @@ SKO: # # Table name: partners # -# id :integer not null, primary key +# id :bigint not null, primary key # authentication_token :string(255) # confirmed :boolean # current_sign_in_at :datetime @@ -40,21 +40,21 @@ SKO: # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string(255) -# sign_in_count :integer default(0), not null +# sign_in_count :bigint default(0), not null # created_at :datetime # updated_at :datetime -# access_level_id :integer -# event_id :integer +# access_level_id :bigint +# event_id :bigint # # Indexes # -# fk_rails_188986c214 (event_id) -# index_partners_on_access_level_id (access_level_id) -# index_partners_on_authentication_token (authentication_token) -# index_partners_on_reset_password_token (reset_password_token) UNIQUE +# idx_16916_fk_rails_188986c214 (event_id) +# idx_16916_index_partners_on_access_level_id (access_level_id) +# idx_16916_index_partners_on_authentication_token (authentication_token) +# idx_16916_index_partners_on_reset_password_token (reset_password_token) UNIQUE # # Foreign Keys # -# fk_rails_... (access_level_id => access_levels.id) -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (access_level_id => access_levels.id) ON DELETE => restrict ON UPDATE => restrict +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/fixtures/registrations.yml b/test/fixtures/registrations.yml index 06195e0f..7d3c3955 100644 --- a/test/fixtures/registrations.yml +++ b/test/fixtures/registrations.yml @@ -75,32 +75,32 @@ capacity_registration_<%= n %>: # # Table name: registrations # -# id :integer not null, primary key +# id :bigint not null, primary key # barcode :string(255) # barcode_data :string(255) # checked_in_at :datetime -# comment :text(65535) +# comment :text # email :string(255) # name :string(255) -# paid :integer +# paid :bigint # payment_code :string(255) -# price :integer +# price :bigint # student_number :string(255) # token :string(255) not null # created_at :datetime # updated_at :datetime -# access_level_id :integer not null -# event_id :integer +# access_level_id :bigint not null +# event_id :bigint # # Indexes # -# index_registrations_on_access_level_id (access_level_id) -# index_registrations_on_event_id (event_id) -# index_registrations_on_payment_code (payment_code) UNIQUE -# index_registrations_on_token (token) +# idx_16930_index_registrations_on_access_level_id (access_level_id) +# idx_16930_index_registrations_on_event_id (event_id) +# idx_16930_index_registrations_on_payment_code (payment_code) UNIQUE +# idx_16930_index_registrations_on_token (token) # # Foreign Keys # -# fk_rails_... (access_level_id => access_levels.id) -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (access_level_id => access_levels.id) ON DELETE => restrict ON UPDATE => restrict +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index cba9ea7e..a04c1301 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -8,7 +8,7 @@ tom: username: tnnaesse - cas_ugentStudentID: 00800857 + cas_ugentstudentid: 00800857 clubs: - zeus @@ -35,24 +35,24 @@ adminfelix: # # Table name: users # -# id :integer not null, primary key +# id :bigint not null, primary key # admin :boolean # cas_givenname :string(255) # cas_mail :string(255) # cas_surname :string(255) -# cas_ugentStudentID :string(255) +# cas_ugentstudentid :string(255) # cas_uid :string(255) # current_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_at :datetime # last_sign_in_ip :string(255) # remember_created_at :datetime -# sign_in_count :integer default(0), not null +# sign_in_count :bigint default(0), not null # username :string(255) not null # created_at :datetime # updated_at :datetime # # Indexes # -# index_users_on_username (username) UNIQUE +# idx_16946_index_users_on_username (username) UNIQUE # diff --git a/test/models/access_level_test.rb b/test/models/access_level_test.rb index 99455380..80b2e7f5 100644 --- a/test/models/access_level_test.rb +++ b/test/models/access_level_test.rb @@ -14,22 +14,22 @@ class AccessLevelTest < ActiveSupport::TestCase # # Table name: access_levels # -# id :integer not null, primary key -# capacity :integer +# id :bigint not null, primary key +# capacity :bigint # has_comment :boolean # hidden :boolean # name :string(255) # permit :string(255) default("everyone") -# price :integer +# price :bigint # created_at :datetime # updated_at :datetime -# event_id :integer +# event_id :bigint # # Indexes # -# index_access_levels_on_event_id (event_id) +# idx_16847_index_access_levels_on_event_id (event_id) # # Foreign Keys # -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/models/club_test.rb b/test/models/club_test.rb index 2765ee9e..e06286d3 100644 --- a/test/models/club_test.rb +++ b/test/models/club_test.rb @@ -14,7 +14,7 @@ class ClubTest < ActiveSupport::TestCase # # Table name: clubs # -# id :integer not null, primary key +# id :bigint not null, primary key # display_name :string(255) # full_name :string(255) # internal_name :string(255) @@ -23,5 +23,5 @@ class ClubTest < ActiveSupport::TestCase # # Indexes # -# index_clubs_on_internal_name (internal_name) UNIQUE +# idx_16882_index_clubs_on_internal_name (internal_name) UNIQUE # diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 81c319f4..4c37d066 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -27,14 +27,14 @@ class EventTest < ActiveSupport::TestCase # # Table name: events # -# id :integer not null, primary key +# id :bigint not null, primary key # bank_number :string(255) # contact_email :string(255) -# description :text(16777215) +# description :text # end_date :datetime # export_content_type :string(255) # export_file_name :string(255) -# export_file_size :integer +# export_file_size :bigint # export_status :string(255) # export_updated_at :datetime # location :string(255) @@ -45,18 +45,18 @@ class EventTest < ActiveSupport::TestCase # require_physical_ticket :boolean default(FALSE), not null # show_statistics :boolean # show_ticket_count :boolean default(TRUE) -# signature :text(65535) +# signature :text # start_date :datetime # website :string(255) # created_at :datetime # updated_at :datetime -# club_id :integer +# club_id :bigint # # Indexes # -# fk_rails_fc45ac705d (club_id) +# idx_16898_fk_rails_fc45ac705d (club_id) # # Foreign Keys # -# fk_rails_... (club_id => clubs.id) ON DELETE => cascade +# fk_rails_... (club_id => clubs.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/models/partner_test.rb b/test/models/partner_test.rb index d2885dc0..34420282 100644 --- a/test/models/partner_test.rb +++ b/test/models/partner_test.rb @@ -13,7 +13,7 @@ class PartnerTest < ActiveSupport::TestCase # # Table name: partners # -# id :integer not null, primary key +# id :bigint not null, primary key # authentication_token :string(255) # confirmed :boolean # current_sign_in_at :datetime @@ -25,21 +25,21 @@ class PartnerTest < ActiveSupport::TestCase # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string(255) -# sign_in_count :integer default(0), not null +# sign_in_count :bigint default(0), not null # created_at :datetime # updated_at :datetime -# access_level_id :integer -# event_id :integer +# access_level_id :bigint +# event_id :bigint # # Indexes # -# fk_rails_188986c214 (event_id) -# index_partners_on_access_level_id (access_level_id) -# index_partners_on_authentication_token (authentication_token) -# index_partners_on_reset_password_token (reset_password_token) UNIQUE +# idx_16916_fk_rails_188986c214 (event_id) +# idx_16916_index_partners_on_access_level_id (access_level_id) +# idx_16916_index_partners_on_authentication_token (authentication_token) +# idx_16916_index_partners_on_reset_password_token (reset_password_token) UNIQUE # # Foreign Keys # -# fk_rails_... (access_level_id => access_levels.id) -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (access_level_id => access_levels.id) ON DELETE => restrict ON UPDATE => restrict +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/models/registration_test.rb b/test/models/registration_test.rb index 0adbf851..d9c8f084 100644 --- a/test/models/registration_test.rb +++ b/test/models/registration_test.rb @@ -68,32 +68,32 @@ def teardown # # Table name: registrations # -# id :integer not null, primary key +# id :bigint not null, primary key # barcode :string(255) # barcode_data :string(255) # checked_in_at :datetime -# comment :text(65535) +# comment :text # email :string(255) # name :string(255) -# paid :integer +# paid :bigint # payment_code :string(255) -# price :integer +# price :bigint # student_number :string(255) # token :string(255) not null # created_at :datetime # updated_at :datetime -# access_level_id :integer not null -# event_id :integer +# access_level_id :bigint not null +# event_id :bigint # # Indexes # -# index_registrations_on_access_level_id (access_level_id) -# index_registrations_on_event_id (event_id) -# index_registrations_on_payment_code (payment_code) UNIQUE -# index_registrations_on_token (token) +# idx_16930_index_registrations_on_access_level_id (access_level_id) +# idx_16930_index_registrations_on_event_id (event_id) +# idx_16930_index_registrations_on_payment_code (payment_code) UNIQUE +# idx_16930_index_registrations_on_token (token) # # Foreign Keys # -# fk_rails_... (access_level_id => access_levels.id) -# fk_rails_... (event_id => events.id) ON DELETE => cascade +# fk_rails_... (access_level_id => access_levels.id) ON DELETE => restrict ON UPDATE => restrict +# fk_rails_... (event_id => events.id) ON DELETE => cascade ON UPDATE => restrict # diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 51e23ea1..ebaad28e 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -10,24 +10,24 @@ class UserTest < ActiveSupport::TestCase # # Table name: users # -# id :integer not null, primary key +# id :bigint not null, primary key # admin :boolean # cas_givenname :string(255) # cas_mail :string(255) # cas_surname :string(255) -# cas_ugentStudentID :string(255) +# cas_ugentstudentid :string(255) # cas_uid :string(255) # current_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_at :datetime # last_sign_in_ip :string(255) # remember_created_at :datetime -# sign_in_count :integer default(0), not null +# sign_in_count :bigint default(0), not null # username :string(255) not null # created_at :datetime # updated_at :datetime # # Indexes # -# index_users_on_username (username) UNIQUE +# idx_16946_index_users_on_username (username) UNIQUE # From 796d0e0f4e3711229b245e3858089df8070522a8 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Sun, 19 May 2024 14:06:19 +0200 Subject: [PATCH 3/3] Passing pipeline --- app/controllers/events_controller.rb | 6 +++--- app/controllers/registrations_controller.rb | 2 +- app/models/ability.rb | 2 +- app/models/registration.rb | 2 -- docker-compose.yml | 1 - 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 0d6a0cab..07c086cf 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -8,9 +8,9 @@ class EventsController < ApplicationController respond_to :html, :js, :ics def index - @events = Event.where('end_date > ?', DateTime.now).order(:start_date) + @events = Event.where('end_date > ?', DateTime.now).order(start_date: :asc) @past_events = if user_signed_in? - Event.accessible_by(current_ability).order(:name) + Event.accessible_by(current_ability).order(start_date: :desc) else [] end @@ -84,7 +84,7 @@ def statistics @data = @event.access_levels.map do |al| { name: al.name, - data: zeros.merge(al.registrations.group('registrations.name, date(registrations.created_at)').count.transform_keys { |key| key.strftime("%Y-%m-%d") }) + data: zeros.merge(al.registrations.group('date(registrations.created_at)').count.transform_keys { |key| key.strftime("%Y-%m-%d") }) } end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 74e9d6d7..9ac091dc 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -12,7 +12,7 @@ def index authorize! :read, @event - @registrationsgrid = RegistrationsGrid.new(params[:registrations_grid]) do |scope| + @registrationsgrid = RegistrationsGrid.new(order: :name, **params.fetch(:registrations_grid, {}).permit!) do |scope| scope.where(event_id: @event.id).order(Arel.sql("registrations.price - paid DESC")) end diff --git a/app/models/ability.rb b/app/models/ability.rb index eadff5b7..47acff51 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -32,7 +32,7 @@ def user_rules(user) if clubs.present? can :create, Event can :show, Event - can :crud, Event, ["? IN (?)", :club_id, clubs.pluck(:id)] do |e| + can :crud, Event, ["club_id IN (?)", clubs.ids] do |e| clubs.include? e.club end else diff --git a/app/models/registration.rb b/app/models/registration.rb index 3dfbcdee..84c3296f 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -35,8 +35,6 @@ class Registration < ApplicationRecord end end - default_scope { order "name ASC" } - def paid from_cents read_attribute(:paid) end diff --git a/docker-compose.yml b/docker-compose.yml index 00859585..0e82e694 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,6 @@ services: - "6379:6379" volumes: - db_data: gandalf_data: gandalf_test_data: redis_data: