group BusinessAccountField;

CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"

getFieldsForAccountByKey(account_key) ::=<<
select
  account_id
, account_key
, name
, value
from bac_fields
where account_key = :account_key
<AND_CHECK_TENANT()>
;
>>

addField(account_id, account_key, name, value) ::=<<
insert into bac_fields (
  account_id
, account_key
, name
, value
, account_record_id
, tenant_record_id
) values (
  :account_id
, :account_key
, :name
, :value
, :accountRecordId
, :tenantRecordId
);
>>

removeField(account_id, name) ::= <<
delete from bac_fields where account_id = :account_id and name = :name <AND_CHECK_TENANT()>;
>>

test() ::= <<
select 1 from bac_fields where <CHECK_TENANT()>;
>>
