Skip to content

Commit

Permalink
Merge pull request #3850 from akostadinov/tenant_id_restore
Browse files Browse the repository at this point in the history
THREESCALE-7183 onboardings tenant_id fix
  • Loading branch information
akostadinov authored Jul 22, 2024
2 parents eab8b6a + e07939c commit 59fdfcc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
15 changes: 15 additions & 0 deletions db/migrate/20240719174715_onboardings_tenant_id_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class OnboardingsTenantIdFix < ActiveRecord::Migration[6.1]
def up
triggers = System::Database.triggers.select { |trigger| trigger.table =~ /\Aonboardings\z/ }
ActiveRecord::Base.transaction do
triggers.each do |trigger|
expressions = [trigger.public_send(:recreate)].flatten
expressions.each(&ActiveRecord::Base.connection.method(:execute))
end
end

Onboarding.update_all(tenant_id: nil)
end
end
2 changes: 1 addition & 1 deletion db/oracle_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_07_04_135614) do
ActiveRecord::Schema.define(version: 2024_07_19_174715) do

create_table "access_tokens", force: :cascade do |t|
t.integer "owner_id", precision: 38, null: false
Expand Down
2 changes: 1 addition & 1 deletion db/postgres_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_07_04_135614) do
ActiveRecord::Schema.define(version: 2024_07_19_174715) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_07_04_135614) do
ActiveRecord::Schema.define(version: 2024_07_19_174715) do

create_table "access_tokens", charset: "utf8mb3", collation: "utf8mb3_bin", force: :cascade do |t|
t.bigint "owner_id", null: false
Expand Down
4 changes: 1 addition & 3 deletions lib/system/database/definitions/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@

trigger 'onboardings' do
<<~SQL
IF NEW.account_id <> master_id THEN
SET NEW.tenant_id = NEW.account_id;
END IF;
SET NEW.tenant_id = (SELECT tenant_id FROM accounts WHERE id = NEW.account_id AND tenant_id <> master_id);
SQL
end

Expand Down
4 changes: 1 addition & 3 deletions lib/system/database/definitions/oracle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@

trigger 'onboardings' do
<<~SQL
IF :new.account_id <> master_id THEN
:new.tenant_id := :new.account_id;
END IF;
SELECT tenant_id INTO :new.tenant_id FROM accounts WHERE id = :new.account_id AND tenant_id <> master_id;
SQL
end

Expand Down
4 changes: 1 addition & 3 deletions lib/system/database/definitions/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@

trigger 'onboardings' do
<<~SQL
IF NEW.account_id <> master_id THEN
NEW.tenant_id := NEW.account_id;
END IF;
SELECT tenant_id INTO NEW.tenant_id FROM accounts WHERE id = NEW.account_id AND tenant_id <> master_id;
SQL
end

Expand Down
11 changes: 11 additions & 0 deletions test/integration/buyers/users_controller_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ def setup
assert_equal 'newemail@example.org', user.email
assert_equal 'Japan', user.field_value('country')
end

test "#activate" do
user = FactoryBot.create(:pending_user, account: buyer)
assert_not user.active?

post activate_admin_buyers_account_user_path(account_id: buyer.id, id: user.id)
follow_redirect!

assert_response :ok
assert user.reload.active?
end
end

0 comments on commit 59fdfcc

Please sign in to comment.