Skip to content

Commit

Permalink
Merge pull request #161 from hitobito/psql-migration
Browse files Browse the repository at this point in the history
psql-migration
  • Loading branch information
Vakmeth authored Aug 30, 2024
2 parents 66d42e0 + 36b023b commit 51ed341
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
default: 'master'
jobs:
wagon_tests:
uses: hitobito/hitobito/.github/workflows/wagon-tests.yml@master
uses: hitobito/hitobito/.github/workflows/wagon-tests.yml@psql-migration
with:
wagon_repository: ${{ github.event.repository.name }}
core_ref: ${{ inputs.core_ref }}
Expand Down
2 changes: 0 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ load "rspec/rails/tasks/rspec.rake"
require "ci/reporter/rake/rspec" unless Rails.env.production?

HitobitoInsieme::Wagon.load_tasks

task "test:prepare" => "db:test:prepare"
8 changes: 4 additions & 4 deletions app/domain/fp2015/course_reporting/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def total(course_records)
end

def select_clause
columns = ["event_course_records.year",
"event_course_records.kursart",
"event_course_records.inputkriterien",
"event_course_records.event_id"]
columns = ["MIN(event_course_records.year) AS year",
"MIN(event_course_records.kursart) AS kursart",
"MIN(event_course_records.inputkriterien) AS inputkriterien",
"MIN(event_course_records.event_id) AS event_id"]
columns.concat(sql_summed_attrs)
columns << sql_sum_unterkunft
columns.join(", ")
Expand Down
11 changes: 6 additions & 5 deletions app/domain/fp2020/course_reporting/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def build_totals(hash)
end

def records_for(attr, value)
records.select { |record| record.send(attr) == value }
Event::Course.first.fachkonzept
records.select { |record| record.event.send(attr) == value }
end

def find_record(fachkonzept, kursart)
Expand Down Expand Up @@ -136,10 +137,10 @@ def total(course_records)
end

def select_clause
columns = ["event_course_records.year",
"event_course_records.kursart",
"events.fachkonzept",
"event_course_records.event_id"]
columns = ["MIN(event_course_records.year) AS year",
"MIN(event_course_records.kursart) AS kursart",
"MIN(events.fachkonzept) AS fachkonzept",
"MIN(event_course_records.event_id) AS event_id"]
columns.concat(sql_summed_attrs)
columns << sql_sum_unterkunft
columns.join(", ")
Expand Down
4 changes: 2 additions & 2 deletions app/domain/fp2020/course_reporting/client_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def group_canton_participants

def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
columns = [
"`groups`.id AS group_id",
"MAX(groups.id) AS group_id",
"events.leistungskategorie AS event_leistungskategorie"
]

Expand Down Expand Up @@ -103,7 +103,7 @@ def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Me
CASE events.leistungskategorie
WHEN 'tp' THEN 0
ELSE
CASE events.type
CASE MAX(events.type)
WHEN 'Event::AggregateCourse' THEN
SUM(COALESCE(event_course_records.tage_weitere, 0))
ELSE
Expand Down
8 changes: 4 additions & 4 deletions app/domain/fp2020/time_record/lufeb_pro_verein.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def time_records # rubocop:disable Metrics/MethodLength
.group(:group_id)
.select([
"group_id",
"SUM(total_lufeb_general) AS `general`",
"SUM(total_lufeb_specific) AS `specific`",
"SUM(total_lufeb_promoting) AS `promoting`",
"SUM(lufeb_grundlagen) AS `lufeb_grundlagen`",
"SUM(total_lufeb_general) AS general",
"SUM(total_lufeb_specific) AS specific",
"SUM(total_lufeb_promoting) AS promoting",
"SUM(lufeb_grundlagen) AS lufeb_grundlagen",
"SUM(kurse_grundlagen) AS kurse_grundlagen"
].join(", "))
.all
Expand Down
10 changes: 5 additions & 5 deletions app/domain/fp2022/course_reporting/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def build_totals(hash)
end

def records_for(attr, value)
records.select { |record| record.send(attr) == value }
records.select { |record| record.event.send(attr) == value }
end

def find_record(fachkonzept, kursart)
Expand Down Expand Up @@ -136,10 +136,10 @@ def total(course_records)
end

def select_clause
columns = ["event_course_records.year",
"event_course_records.kursart",
"events.fachkonzept",
"event_course_records.event_id"]
columns = ["MIN(event_course_records.year) AS year",
"MIN(event_course_records.kursart) AS kursart",
"MIN(events.fachkonzept) AS fachkonzept",
"MIN(event_course_records.event_id) AS event_id"]
columns.concat(sql_summed_attrs)
columns << sql_sum_unterkunft
columns.join(", ")
Expand Down
4 changes: 2 additions & 2 deletions app/domain/fp2022/course_reporting/client_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def group_canton_participants

def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
columns = [
"`groups`.id AS group_id",
"MAX(groups.id) AS group_id",
"events.leistungskategorie AS event_leistungskategorie"
]

Expand Down Expand Up @@ -103,7 +103,7 @@ def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Me
CASE events.leistungskategorie
WHEN 'tp' THEN 0
ELSE
CASE events.type
CASE MAX(events.type)
WHEN 'Event::AggregateCourse' THEN
SUM(COALESCE(event_course_records.tage_weitere, 0))
ELSE
Expand Down
8 changes: 4 additions & 4 deletions app/domain/fp2022/time_record/lufeb_pro_verein.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def time_records # rubocop:disable Metrics/MethodLength
.group(:group_id)
.select([
"group_id",
"SUM(total_lufeb_general) AS `general`",
"SUM(total_lufeb_specific) AS `specific`",
"SUM(total_lufeb_promoting) AS `promoting`",
"SUM(lufeb_grundlagen) AS `lufeb_grundlagen`",
"SUM(total_lufeb_general) AS general",
"SUM(total_lufeb_specific) AS specific",
"SUM(total_lufeb_promoting) AS promoting",
"SUM(lufeb_grundlagen) AS lufeb_grundlagen",
"SUM(kurse_grundlagen) AS kurse_grundlagen"
].join(", "))
.all
Expand Down
14 changes: 7 additions & 7 deletions app/domain/statistics/vereinsmitglieder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def type_counts
end

def type_counts_per_layer
result = Role.connection.execute(type_counts_per_layer_query)
result = Role.connection.execute(type_counts_per_layer_query).to_a
result.each_with_object({}) do |row, hash|
hash[row[0]] ||= Hash.new(0)
hash[row[0]][row[1]] = row[2]
hash[row["layer_group_id"]] ||= Hash.new(0)
hash[row["layer_group_id"]][row["type_index"]] = row["count"]
end
end

Expand All @@ -54,16 +54,16 @@ def type_counts_per_layer_query

def person_roles_per_layer_query
<<-SQL
SELECT `groups`.layer_group_id AS layer_group_id,
SELECT "groups".layer_group_id AS layer_group_id,
MIN(#{type_index_switch}) AS type_index,
roles.person_id AS person_id
FROM roles
INNER JOIN `groups` `groups` ON `groups`.id = roles.group_id
INNER JOIN `groups` layers ON layers.id = `groups`.layer_group_id
INNER JOIN "groups" "groups" ON "groups".id = roles.group_id
INNER JOIN "groups" layers ON layers.id = "groups".layer_group_id
WHERE layers.type = '#{Group::Regionalverein.sti_name}' AND
roles.deleted_at IS NULL AND
roles.type IN (#{role_types_param})
GROUP BY `groups`.layer_group_id,
GROUP BY "groups".layer_group_id,
roles.person_id
SQL
end
Expand Down
12 changes: 0 additions & 12 deletions app/indices/person_index.rb

This file was deleted.

5 changes: 4 additions & 1 deletion app/models/insieme/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module Insieme::Person

Person::PUBLIC_ATTRS << :number << :salutation << :correspondence_language

Person::SEARCHABLE_ATTRS << :number << :salutation << :canton
include PgSearchable

ADDRESS_TYPES.each do |prefix|
ADDRESS_FIELDS.each do |field|
Person::PUBLIC_ATTRS << :"#{prefix}_#{field}"
Expand Down Expand Up @@ -72,7 +75,7 @@ def grouped_active_membership_roles
if @grouped_active_membership_roles.nil?
active_memberships = roles.includes(:group)
.joins(:group)
.where(groups: {type: ::Group::Aktivmitglieder})
.where(groups: {type: ::Group::Aktivmitglieder.sti_name})
@grouped_active_membership_roles = Hash.new { |h, k| h[k] = [] }
active_memberships.each do |role|
@grouped_active_membership_roles[role.group] << role
Expand Down
36 changes: 18 additions & 18 deletions spec/domain/fp2015/export/tabular/statistics/group_figures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ def export(figures)
]

expect(data.second).to eq [
"Biel-Seeland", "Bern", nil, 3115,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0, 0, 0,
0, 0, 0, 0,
0,
0.0, 0.0, 0.0, 0.0, 0.0,
-200000.0, 0.0, 0.0, 0.0, 0.0
]

expect(data.third).to eq [
"Freiburg", "Freiburg", nil, 12607,
1, 0.0, 1545.0, 0.0, 0.0, 1545.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
Expand All @@ -207,7 +224,7 @@ def export(figures)
-185550.0, 0.0, 1100.0, 0.0, -1100.0
]

expect(data.third).to eq [
expect(data.fourth).to eq [
"Kanton Bern", "Bern", nil, 2024,
2, 1100.0, 1000.0, 1111.0, 0.0, 2111.0,
1, 800.0, 5400.0, 0.0, 0.0, 5400.0,
Expand All @@ -223,23 +240,6 @@ def export(figures)
0.25, 0.25, (50.0 / 1900).round(5), (50.0 / 1900).round(5), (20.0 / 1900).round(5),
10_074_000.0, 100.0, 2050.0, 20.0, -2000.0
]

expect(data.fourth).to eq [
"Biel-Seeland", "Bern", nil, 3115,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0, 0, 0,
0, 0, 0, 0,
0,
0.0, 0.0, 0.0, 0.0, 0.0,
-200000.0, 0.0, 0.0, 0.0, 0.0
]
end

def create_course(year, group_key, leistungskategorie, kategorie, attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
context "for employee time" do
it "contains all data" do
data = export
expect(data[2]).to eq(["Kanton Bern",
expect(data[3]).to eq(["Kanton Bern",
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0,
200, nil, nil, 330, 530,
nil, nil, nil, nil, nil, 0,
Expand Down Expand Up @@ -154,7 +154,7 @@

it "contains all data" do
data = export
expect(data[2]).to eq(["Kanton Bern",
expect(data[3]).to eq(["Kanton Bern",
300,
nil,
nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
end

it "for Freiburg" do
expect(data.second).to include(empty_row.merge({
expect(data.third).to include(empty_row.merge({
"Vollständiger Name" => "Freiburg",
"Kanton" => "Freiburg",
"VID" => nil,
Expand Down Expand Up @@ -443,7 +443,7 @@

it "for Kanton Bern" do
# 30 Stunden für LUFEB / 1900 BSV-Stunden
expect(data.third).to include(empty_row.merge({
expect(data.fourth).to include(empty_row.merge({
"Vollständiger Name" => "Kanton Bern",
"Kanton" => "Bern",
"BSV Nummer" => 2024,
Expand Down Expand Up @@ -510,7 +510,7 @@
end

it "for Biel-Seeland" do
expect(data.fourth).to include(empty_row.merge({
expect(data.second).to include(empty_row.merge({
"Vollständiger Name" => "Biel-Seeland",
"Kanton" => "Bern",
"BSV Nummer" => 3115,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
context "for employee time" do
it "contains all data" do
data = export
expect(data[2]).to eq(["Kanton Bern",
expect(data[3]).to eq(["Kanton Bern",
nil, nil, nil, nil, 0,
nil, nil, nil, nil, 0,
nil, nil, nil, nil, 0, 0,
Expand Down Expand Up @@ -163,7 +163,7 @@

it "contains all data" do
data = export
expect(labels.zip(data[2]).to_h).to eq empty_row.merge({
expect(labels.zip(data[3]).to_h).to eq empty_row.merge({
"Gruppe" => "Kanton Bern",

"Allgemeine Medien- und Öffentlichkeitsarbeit" => 300,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
end

it "for Freiburg" do
expect(data.second).to include(empty_row.merge({
expect(data.third).to include(empty_row.merge({
"Vollständiger Name" => "Freiburg",
"Kanton" => "Freiburg",
"VID" => nil,
Expand Down Expand Up @@ -452,7 +452,7 @@

it "for Kanton Bern" do
# 30 Stunden für LUFEB / 1900 BSV-Stunden
expect(data.third).to include(empty_row.merge({
expect(data.fourth).to include(empty_row.merge({
"Vollständiger Name" => "Kanton Bern",
"Kanton" => "Bern",
"BSV Nummer" => 2024,
Expand Down Expand Up @@ -522,7 +522,7 @@
end

it "for Biel-Seeland" do
expect(data.fourth).to include(empty_row.merge({
expect(data.second).to include(empty_row.merge({
"Vollständiger Name" => "Biel-Seeland",
"Kanton" => "Bern",
"BSV Nummer" => 3115,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
context "for employee time" do
it "contains all data" do
data = export
expect(data[2]).to eq(["Kanton Bern",
expect(data[3]).to eq(["Kanton Bern",
nil, nil, nil, nil, 0,
nil, nil, nil, nil, 0,
nil, nil, nil, nil, 0, 0,
Expand Down Expand Up @@ -165,7 +165,7 @@

it "contains all data" do
data = export
expect(labels.zip(data[2]).to_h).to eq empty_row.merge({
expect(labels.zip(data[3]).to_h).to eq empty_row.merge({
"Gruppe" => "Kanton Bern",

"Allgemeine Medien- und Öffentlichkeitsarbeit" => 300,
Expand Down
Loading

0 comments on commit 51ed341

Please sign in to comment.