def account_approvers(account)
User.
where(id: AccountMembership.
where('is_approver OR is_admin').
where(account_id: account.id, suspended: false).
select(:user_id)).
or(User.where(id: BkMembership.
where(account_id: account.parent_account_id, client_account_id: account.id).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'wombat' | |
gem 'pry' | |
end | |
puts 'Gems installed and loaded!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def account_approvers_except(account) | |
User.where(<<-SQL, account_id: account.id, parent_account_id: account.parent_account_id) | |
id IN ( | |
( | |
SELECT account_memberships.user_id | |
FROM account_memberships | |
WHERE account_id = :account_id AND (is_approver OR is_admin) | |
UNION ALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.connection.execute(<<-SQL) | |
DROP TABLE IF EXISTS non_duplicate_brand_tuples; | |
CREATE TABLE non_duplicate_brand_tuples ( | |
id serial primary key, | |
main_brand_id integer NOT NULL, | |
non_duplicate_brand_id integer NOT NULL | |
); | |
SQL | |
class NonDuplicateBrandTuples < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS non_duplicate_cat_typles') | |
ActiveRecord::Base.connection.execute(<<-SQL) | |
CREATE TABLE non_duplicate_cat_typles ( | |
id serial primary key, | |
main_id integer NOT NULL, | |
non_duplicate_id integer NOT NULL | |
); | |
SQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initialization file (not found) |