Use standard column names (#138)
This commit is contained in:
1 parent
766c174fe9
commit
6908f7a7a2
3 files changed
+39
-37
No files matched your search
+11
-11
@@ -13,13 +13,13 @@ func TestDB_AuthMethodIDTrigger(t *testing.T) {
|
||||
const (
|
||||
createTable = `
|
||||
create table if not exists test_auth_method (
|
||||
auth_method_id wt_public_id primary key,
|
||||
iam_scope_id wt_public_id not null references iam_scope(public_id)
|
||||
public_id wt_public_id primary key,
|
||||
scope_id wt_public_id not null references iam_scope(public_id)
|
||||
);
|
||||
`
|
||||
insert = `
|
||||
insert into test_auth_method
|
||||
(auth_method_id, iam_scope_id)
|
||||
(public_id, scope_id)
|
||||
values
|
||||
($1, $2);
|
||||
`
|
||||
@@ -31,10 +31,10 @@ insert on test_auth_method
|
||||
for each row execute procedure insert_auth_method_subtype();
|
||||
`
|
||||
baseTableQuery = `
|
||||
select count(*) from auth_method where auth_method_id = $1;
|
||||
select count(*) from auth_method where public_id = $1;
|
||||
`
|
||||
testTableQuery = `
|
||||
select count(*) from test_auth_method where auth_method_id = $1;
|
||||
select count(*) from test_auth_method where public_id = $1;
|
||||
`
|
||||
)
|
||||
|
||||
@@ -81,14 +81,14 @@ func TestDB_AuthAccountIDTrigger(t *testing.T) {
|
||||
const (
|
||||
createTable = `
|
||||
create table if not exists test_auth_account (
|
||||
auth_account_id wt_public_id primary key,
|
||||
public_id wt_public_id primary key,
|
||||
auth_method_id wt_public_id not null,
|
||||
iam_scope_id wt_public_id not null
|
||||
scope_id wt_public_id not null
|
||||
);
|
||||
`
|
||||
insert = `
|
||||
insert into test_auth_account
|
||||
(auth_account_id, auth_method_id, iam_scope_id)
|
||||
(public_id, auth_method_id, scope_id)
|
||||
values
|
||||
($1, $2, $3);
|
||||
`
|
||||
@@ -100,14 +100,14 @@ insert on test_auth_account
|
||||
for each row execute procedure insert_auth_account_subtype();
|
||||
`
|
||||
baseTableQuery = `
|
||||
select count(*) from auth_account where auth_account_id = $1;
|
||||
select count(*) from auth_account where public_id = $1;
|
||||
`
|
||||
testTableQuery = `
|
||||
select count(*) from test_auth_account where auth_account_id = $1;
|
||||
select count(*) from test_auth_account where public_id = $1;
|
||||
`
|
||||
insertAuthMethod = `
|
||||
insert into auth_method
|
||||
(auth_method_id, iam_scope_id)
|
||||
(public_id, scope_id)
|
||||
values
|
||||
($1, $2);
|
||||
`
|
||||
|
||||
@@ -622,8 +622,8 @@ begin;
|
||||
|
||||
-- base table for auth methods
|
||||
create table auth_method (
|
||||
auth_method_id wt_public_id primary key,
|
||||
iam_scope_id wt_public_id not null
|
||||
public_id wt_public_id primary key,
|
||||
scope_id wt_public_id not null
|
||||
references iam_scope(public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
@@ -631,24 +631,25 @@ begin;
|
||||
-- The order of columns is important for performance. See:
|
||||
-- https://dba.stackexchange.com/questions/58970/enforcing-constraints-two-tables-away/58972#58972
|
||||
-- https://dba.stackexchange.com/questions/27481/is-a-composite-index-also-good-for-queries-on-the-first-field
|
||||
unique(iam_scope_id, auth_method_id)
|
||||
unique(scope_id, public_id)
|
||||
);
|
||||
|
||||
|
||||
-- base table for auth accounts
|
||||
create table auth_account (
|
||||
auth_account_id wt_public_id primary key,
|
||||
public_id wt_public_id primary key,
|
||||
auth_method_id wt_public_id not null,
|
||||
iam_scope_id wt_public_id not null,
|
||||
scope_id wt_public_id not null,
|
||||
iam_user_id wt_public_id,
|
||||
foreign key (iam_scope_id, auth_method_id)
|
||||
references auth_method (iam_scope_id, auth_method_id)
|
||||
foreign key (scope_id, auth_method_id)
|
||||
references auth_method (scope_id, public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
foreign key (iam_scope_id, iam_user_id)
|
||||
foreign key (scope_id, iam_user_id)
|
||||
references iam_user (scope_id, public_id)
|
||||
on delete set null
|
||||
on update cascade
|
||||
on update cascade,
|
||||
unique(scope_id, auth_method_id, public_id)
|
||||
);
|
||||
|
||||
|
||||
@@ -658,9 +659,9 @@ begin;
|
||||
as $$
|
||||
begin
|
||||
insert into auth_method
|
||||
(auth_method_id, iam_scope_id)
|
||||
(public_id, scope_id)
|
||||
values
|
||||
(new.auth_method_id, new.iam_scope_id);
|
||||
(new.public_id, new.scope_id);
|
||||
return new;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
@@ -671,9 +672,9 @@ begin;
|
||||
as $$
|
||||
begin
|
||||
insert into auth_account
|
||||
(auth_account_id, auth_method_id, iam_scope_id)
|
||||
(public_id, auth_method_id, scope_id)
|
||||
values
|
||||
(new.auth_account_id, new.auth_method_id, new.iam_scope_id);
|
||||
(new.public_id, new.auth_method_id, new.scope_id);
|
||||
return new;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
@@ -9,8 +9,8 @@ begin;
|
||||
|
||||
-- base table for auth methods
|
||||
create table auth_method (
|
||||
auth_method_id wt_public_id primary key,
|
||||
iam_scope_id wt_public_id not null
|
||||
public_id wt_public_id primary key,
|
||||
scope_id wt_public_id not null
|
||||
references iam_scope(public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
@@ -18,24 +18,25 @@ begin;
|
||||
-- The order of columns is important for performance. See:
|
||||
-- https://dba.stackexchange.com/questions/58970/enforcing-constraints-two-tables-away/58972#58972
|
||||
-- https://dba.stackexchange.com/questions/27481/is-a-composite-index-also-good-for-queries-on-the-first-field
|
||||
unique(iam_scope_id, auth_method_id)
|
||||
unique(scope_id, public_id)
|
||||
);
|
||||
|
||||
|
||||
-- base table for auth accounts
|
||||
create table auth_account (
|
||||
auth_account_id wt_public_id primary key,
|
||||
public_id wt_public_id primary key,
|
||||
auth_method_id wt_public_id not null,
|
||||
iam_scope_id wt_public_id not null,
|
||||
scope_id wt_public_id not null,
|
||||
iam_user_id wt_public_id,
|
||||
foreign key (iam_scope_id, auth_method_id)
|
||||
references auth_method (iam_scope_id, auth_method_id)
|
||||
foreign key (scope_id, auth_method_id)
|
||||
references auth_method (scope_id, public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
foreign key (iam_scope_id, iam_user_id)
|
||||
foreign key (scope_id, iam_user_id)
|
||||
references iam_user (scope_id, public_id)
|
||||
on delete set null
|
||||
on update cascade
|
||||
on update cascade,
|
||||
unique(scope_id, auth_method_id, public_id)
|
||||
);
|
||||
|
||||
|
||||
@@ -45,9 +46,9 @@ begin;
|
||||
as $$
|
||||
begin
|
||||
insert into auth_method
|
||||
(auth_method_id, iam_scope_id)
|
||||
(public_id, scope_id)
|
||||
values
|
||||
(new.auth_method_id, new.iam_scope_id);
|
||||
(new.public_id, new.scope_id);
|
||||
return new;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
@@ -58,9 +59,9 @@ begin;
|
||||
as $$
|
||||
begin
|
||||
insert into auth_account
|
||||
(auth_account_id, auth_method_id, iam_scope_id)
|
||||
(public_id, auth_method_id, scope_id)
|
||||
values
|
||||
(new.auth_account_id, new.auth_method_id, new.iam_scope_id);
|
||||
(new.public_id, new.auth_method_id, new.scope_id);
|
||||
return new;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
Reference in new issue
Block a user