diff --git a/db/migrate/20230119132734_migrate_to_generated_member_number_2.rb b/db/migrate/20230119132734_migrate_to_generated_member_number_2.rb index e70ec18..51284e0 100644 --- a/db/migrate/20230119132734_migrate_to_generated_member_number_2.rb +++ b/db/migrate/20230119132734_migrate_to_generated_member_number_2.rb @@ -17,8 +17,8 @@ def up FROM ( SELECT DISTINCT person_id FROM roles - WHERE deleted_at IS NULL - OR deleted_at > NOW() + WHERE end_on IS NULL + OR end_on > NOW() ) active_roles WHERE people.id = active_roles.person_id OR manual_member_number >= 300000 diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index ba10b97..e20b81a 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -108,8 +108,8 @@ namespace :import do person_id: person.id, group_id: group.id, type: Group::Mitglieder::Aktivmitglied.sti_name, - created_at: import_row[:memberentrydate], - deleted_at: import_row[:memberexitdate], + start_on: import_row[:memberentrydate], + end_on: import_row[:memberexitdate], updated_at: Time.zone.now } @@ -117,26 +117,26 @@ namespace :import do person_id: person.id, group_id: group.id, type: Group::Mitglieder::MagazinAbonnent.sti_name, - created_at: import_row[:abo1start], - deleted_at: import_row[:abo1end], + start_on: import_row[:abo1start], + end_on: import_row[:abo1end], updated_at: Time.zone.now } [mitglied_attrs, magazin_abo_attrs].each do |attrs| - attrs[:created_at] = DateTime.parse(attrs[:created_at]) if attrs[:created_at] - attrs[:deleted_at] = DateTime.parse(attrs[:deleted_at]) if attrs[:deleted_at] + attrs[:start_on] = DateTime.parse(attrs[:start_on]) if attrs[:start_on] + attrs[:end_on] = DateTime.parse(attrs[:end_on]) if attrs[:end_on] - if attrs[:deleted_at].present? && attrs[:created_at].nil? - attrs[:created_at] = attrs[:deleted_at].yesterday + if attrs[:end_on].present? && attrs[:start_on].nil? + attrs[:start_on] = attrs[:end_on].yesterday end - next unless attrs[:created_at] + next unless attrs[:start_on] # Because of a known issue of the acts_as_paranoid gem, # you can not directly create a model in a deleted state. # Thus we have to update it afterwards. Role.insert(attrs) - Role.with_deleted.last.update(attrs) + Role.with_inactive.last.update(attrs) end tagging_attrs = {taggable_id: person.id, taggable_type: Person.sti_name, context: "tags"} diff --git a/spec/support/graphiti/schema.json b/spec/support/graphiti/schema.json index 34493b1..b4d3dc7 100644 --- a/spec/support/graphiti/schema.json +++ b/spec/support/graphiti/schema.json @@ -2321,8 +2321,14 @@ "writable": false, "description": null }, - "deleted_at": { - "type": "datetime", + "start_on": { + "type": "date", + "readable": true, + "writable": false, + "description": null + }, + "end_on": { + "type": "date", "readable": true, "writable": false, "description": null @@ -2361,7 +2367,9 @@ }, "updated_at": { }, - "deleted_at": { + "start_on": { + }, + "end_on": { }, "person_id": { }, @@ -2406,8 +2414,19 @@ "lte" ] }, - "deleted_at": { - "type": "datetime", + "start_on": { + "type": "date", + "operators": [ + "eq", + "not_eq", + "gt", + "gte", + "lt", + "lte" + ] + }, + "end_on": { + "type": "date", "operators": [ "eq", "not_eq", diff --git a/spec/tasks/import_spec.rb b/spec/tasks/import_spec.rb index 8c3bd50..d875138 100644 --- a/spec/tasks/import_spec.rb +++ b/spec/tasks/import_spec.rb @@ -57,18 +57,18 @@ expect(person.magazin_abo_number).to eq(1000) expect(person.name_add_on).to eq('Mustermann') expect(person.email).to eq('max.muster@example.com') - expect(person.roles.with_deleted.count).to eq(2) + expect(person.roles.with_inactive.count).to eq(2) mitglied = person.roles.first - magazin_abo = person.roles.with_deleted.last + magazin_abo = person.roles.with_inactive.last expect(mitglied.type).to eq(Group::Mitglieder::Aktivmitglied.sti_name) - expect(mitglied.created_at).to eq(DateTime.new(1977, 1, 1)) - expect(mitglied.deleted_at).to be_nil + expect(mitglied.start_on).to eq(DateTime.new(1977, 1, 1)) + expect(mitglied.end_on).to be_nil expect(magazin_abo.type).to eq(Group::Mitglieder::MagazinAbonnent.sti_name) - expect(magazin_abo.created_at).to eq(DateTime.new(1990, 10, 12)) - expect(magazin_abo.deleted_at).to eq(DateTime.new(2006, 2, 12)) + expect(magazin_abo.start_on).to eq(DateTime.new(1990, 10, 12)) + expect(magazin_abo.end_on).to eq(DateTime.new(2006, 2, 12)) expect(person.taggings.count).to eq(3) @@ -107,7 +107,7 @@ expect(person.additional_emails.first.email).to eq('max.muster@example.com') end - it "sets role created_at on a day before deleted_at if not set" do + it "sets role start_on on a day before end_on if not set" do expect do Rake::Task["import:people_fo"].invoke(groups(:berner_wanderwege).id) end.to output("Successfully imported 5/5 rows\n").to_stdout @@ -115,22 +115,22 @@ person = Person.find_by(alabus_id: 'dcwe1-vbsdw2-2cib1kbs-p-g2bnbw1h-2sd') expect(person).to be_present - expect(person.roles.without_deleted.count).to eq(0) - expect(person.roles.with_deleted.count).to eq(2) + expect(person.roles.active.count).to eq(0) + expect(person.roles.with_inactive.count).to eq(2) - mitglied = person.roles.with_deleted.first - magazin_abo = person.roles.with_deleted.last + mitglied = person.roles.with_inactive.first + magazin_abo = person.roles.with_inactive.last expect(mitglied.type).to eq(Group::Mitglieder::Aktivmitglied.sti_name) - expect(mitglied.created_at).to eq(DateTime.new(2002, 11, 29)) - expect(mitglied.deleted_at).to eq(DateTime.new(2002, 11, 30)) + expect(mitglied.start_on).to eq(DateTime.new(2002, 11, 29)) + expect(mitglied.end_on).to eq(DateTime.new(2002, 11, 30)) expect(magazin_abo.type).to eq(Group::Mitglieder::MagazinAbonnent.sti_name) - expect(magazin_abo.created_at).to eq(DateTime.new(1998, 12, 31)) - expect(magazin_abo.deleted_at).to eq(DateTime.new(1999, 1, 1)) + expect(magazin_abo.start_on).to eq(DateTime.new(1998, 12, 31)) + expect(magazin_abo.end_on).to eq(DateTime.new(1999, 1, 1)) end - it "imports role only if created_at can be set" do + it "imports role only if start_on can be set" do expect do Rake::Task["import:people_fo"].invoke(groups(:berner_wanderwege).id) end.to output("Successfully imported 5/5 rows\n").to_stdout @@ -139,9 +139,9 @@ person_with_one_role = Person.find_by(alabus_id: '1s23w-b52n1x-2ciw2kjn-g-g213bwvh-1x7') person_without_roles = Person.find_by(alabus_id: 'bew31-axzcd1-jbhox23z-z-jtxn23wd1-k3g') - expect(person_with_two_roles.roles.with_deleted.count).to eq(2) - expect(person_with_one_role.roles.with_deleted.count).to eq(1) - expect(person_without_roles.roles.with_deleted.count).to eq(0) + expect(person_with_two_roles.roles.with_inactive.count).to eq(2) + expect(person_with_one_role.roles.with_inactive.count).to eq(1) + expect(person_without_roles.roles.with_inactive.count).to eq(0) end it "assigns Schweiz as fallback country" do @@ -381,7 +381,7 @@ expect(person.language).to eq('fr') expect(person.valid_password?('great_password')).to eq(true) - expect(person.roles.with_deleted.count).to eq(1) + expect(person.roles.with_inactive.count).to eq(1) role = Group::Benutzerkonten::Benutzerkonto.find_by(person_id: person.id, group_id: benutzerkonten_group.id)