Prefix table with iam_
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
PersonalAPIKeyMembership struct {
|
PersonalAPIKeyMembership struct {
|
||||||
ID gid.GID `db:"id"`
|
ID gid.GID `db:"id"`
|
||||||
PersonalAPIKeyID gid.GID `db:"auth_personal_api_key_id"`
|
PersonalAPIKeyID gid.GID `db:"personal_api_key_id"`
|
||||||
MembershipID gid.GID `db:"membership_id"`
|
MembershipID gid.GID `db:"membership_id"`
|
||||||
Role APIRole `db:"role"`
|
Role APIRole `db:"role"`
|
||||||
OrganizationID gid.GID `db:"organization_id"`
|
OrganizationID gid.GID `db:"organization_id"`
|
||||||
@@ -47,11 +47,11 @@ func (a *PersonalAPIKeyMembership) Insert(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
authz_api_keys_memberships (id, tenant_id, auth_personal_api_key_id, membership_id, role, organization_id, created_at, updated_at)
|
iam_personal_api_key_memberships (id, tenant_id, personal_api_key_id, membership_id, role, organization_id, created_at, updated_at)
|
||||||
VALUES (
|
VALUES (
|
||||||
@id,
|
@id,
|
||||||
@tenant_id,
|
@tenant_id,
|
||||||
@auth_personal_api_key_id,
|
@personal_api_key_id,
|
||||||
@membership_id,
|
@membership_id,
|
||||||
@role,
|
@role,
|
||||||
@organization_id,
|
@organization_id,
|
||||||
@@ -61,14 +61,14 @@ VALUES (
|
|||||||
`
|
`
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"id": a.ID,
|
"id": a.ID,
|
||||||
"tenant_id": scope.GetTenantID(),
|
"tenant_id": scope.GetTenantID(),
|
||||||
"auth_personal_api_key_id": a.PersonalAPIKeyID,
|
"personal_api_key_id": a.PersonalAPIKeyID,
|
||||||
"membership_id": a.MembershipID,
|
"membership_id": a.MembershipID,
|
||||||
"role": a.Role,
|
"role": a.Role,
|
||||||
"organization_id": a.OrganizationID,
|
"organization_id": a.OrganizationID,
|
||||||
"created_at": a.CreatedAt,
|
"created_at": a.CreatedAt,
|
||||||
"updated_at": a.UpdatedAt,
|
"updated_at": a.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
_, err := conn.Exec(ctx, q, args)
|
||||||
@@ -88,7 +88,7 @@ func (a *PersonalAPIKeyMemberships) LoadByPersonalAPIKeyID(
|
|||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
akm.id,
|
akm.id,
|
||||||
akm.auth_personal_api_key_id,
|
akm.personal_api_key_id,
|
||||||
akm.membership_id,
|
akm.membership_id,
|
||||||
akm.role,
|
akm.role,
|
||||||
akm.created_at,
|
akm.created_at,
|
||||||
@@ -96,13 +96,13 @@ SELECT
|
|||||||
m.organization_id,
|
m.organization_id,
|
||||||
o.name as organization_name
|
o.name as organization_name
|
||||||
FROM
|
FROM
|
||||||
authz_api_keys_memberships akm
|
iam_personal_api_key_memberships akm
|
||||||
JOIN
|
JOIN
|
||||||
authz_memberships m ON akm.membership_id = m.id
|
iam_memberships m ON akm.membership_id = m.id
|
||||||
JOIN
|
JOIN
|
||||||
organizations o ON m.organization_id = o.id
|
organizations o ON m.organization_id = o.id
|
||||||
WHERE
|
WHERE
|
||||||
akm.auth_personal_api_key_id = @auth_personal_api_key_id
|
akm.personal_api_key_id = @personal_api_key_id
|
||||||
AND m.%s
|
AND m.%s
|
||||||
ORDER BY akm.created_at DESC
|
ORDER BY akm.created_at DESC
|
||||||
`
|
`
|
||||||
@@ -110,7 +110,7 @@ ORDER BY akm.created_at DESC
|
|||||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"auth_personal_api_key_id": personalAPIKeyID,
|
"personal_api_key_id": personalAPIKeyID,
|
||||||
}
|
}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
@@ -152,18 +152,18 @@ func (a *PersonalAPIKeyMembership) LoadRoleByAPIKeyAndEntityID(
|
|||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
SELECT
|
SELECT
|
||||||
akm.id,
|
akm.id,
|
||||||
akm.auth_personal_api_key_id,
|
akm.personal_api_key_id,
|
||||||
akm.membership_id,
|
akm.membership_id,
|
||||||
akm.role,
|
akm.role,
|
||||||
akm.created_at,
|
akm.created_at,
|
||||||
akm.updated_at
|
akm.updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_api_keys_memberships akm
|
iam_personal_api_key_memberships akm
|
||||||
INNER JOIN authz_memberships m ON m.id = akm.membership_id
|
INNER JOIN iam_memberships m ON m.id = akm.membership_id
|
||||||
INNER JOIN %s e ON e.id = @entity_id
|
INNER JOIN %s e ON e.id = @entity_id
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND akm.auth_personal_api_key_id = @api_key_id
|
AND akm.personal_api_key_id = @api_key_id
|
||||||
AND m.organization_id = e.organization_id
|
AND m.organization_id = e.organization_id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`, tableName, scope.SQLFragment())
|
`, tableName, scope.SQLFragment())
|
||||||
@@ -212,7 +212,7 @@ func (a *PersonalAPIKeyMembership) LoadByAPIKeyIDAndOrganizationID(
|
|||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
akm.id,
|
akm.id,
|
||||||
akm.auth_personal_api_key_id,
|
akm.personal_api_key_id,
|
||||||
akm.membership_id,
|
akm.membership_id,
|
||||||
akm.role,
|
akm.role,
|
||||||
akm.created_at,
|
akm.created_at,
|
||||||
@@ -220,13 +220,13 @@ SELECT
|
|||||||
m.organization_id,
|
m.organization_id,
|
||||||
o.name as organization_name
|
o.name as organization_name
|
||||||
FROM
|
FROM
|
||||||
authz_api_keys_memberships akm
|
iam_personal_api_key_memberships akm
|
||||||
JOIN
|
JOIN
|
||||||
authz_memberships m ON akm.membership_id = m.id
|
iam_memberships m ON akm.membership_id = m.id
|
||||||
JOIN
|
JOIN
|
||||||
organizations o ON m.organization_id = o.id
|
organizations o ON m.organization_id = o.id
|
||||||
WHERE
|
WHERE
|
||||||
akm.auth_personal_api_key_id = @api_key_id
|
akm.personal_api_key_id = @api_key_id
|
||||||
AND m.organization_id = @organization_id
|
AND m.organization_id = @organization_id
|
||||||
AND m.%s
|
AND m.%s
|
||||||
`
|
`
|
||||||
@@ -263,7 +263,7 @@ func (a *PersonalAPIKeyMembership) Delete(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
authz_api_keys_memberships
|
iam_personal_api_key_memberships
|
||||||
WHERE
|
WHERE
|
||||||
id = @id
|
id = @id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -293,7 +293,7 @@ func (a *PersonalAPIKeyMemberships) LoadByMembershipID(
|
|||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
akm.id,
|
akm.id,
|
||||||
akm.auth_personal_api_key_id,
|
akm.personal_api_key_id,
|
||||||
akm.membership_id,
|
akm.membership_id,
|
||||||
akm.role,
|
akm.role,
|
||||||
akm.created_at,
|
akm.created_at,
|
||||||
@@ -301,9 +301,9 @@ SELECT
|
|||||||
m.organization_id,
|
m.organization_id,
|
||||||
o.name as organization_name
|
o.name as organization_name
|
||||||
FROM
|
FROM
|
||||||
authz_api_keys_memberships akm
|
iam_personal_api_key_memberships akm
|
||||||
JOIN
|
JOIN
|
||||||
authz_memberships m ON akm.membership_id = m.id
|
iam_memberships m ON akm.membership_id = m.id
|
||||||
JOIN
|
JOIN
|
||||||
organizations o ON m.organization_id = o.id
|
organizations o ON m.organization_id = o.id
|
||||||
WHERE
|
WHERE
|
||||||
@@ -341,13 +341,13 @@ func DeleteAllPersonalAPIKeyMembershipsByPersonalAPIKeyID(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
authz_api_keys_memberships
|
iam_personal_api_key_memberships
|
||||||
WHERE
|
WHERE
|
||||||
auth_personal_api_key_id = @auth_personal_api_key_id
|
personal_api_key_id = @personal_api_key_id
|
||||||
`
|
`
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"auth_personal_api_key_id": personalAPIKeyID,
|
"personal_api_key_id": personalAPIKeyID,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
_, err := conn.Exec(ctx, q, args)
|
||||||
|
|||||||
@@ -130,11 +130,11 @@ var entityRegistry = map[uint16]EntityInfo{
|
|||||||
},
|
},
|
||||||
SessionEntityType: {
|
SessionEntityType: {
|
||||||
Model: "Session",
|
Model: "Session",
|
||||||
Table: "auth_sessions",
|
Table: "iam_sessions",
|
||||||
},
|
},
|
||||||
EmailEntityType: {
|
EmailEntityType: {
|
||||||
Model: "Email",
|
Model: "Email",
|
||||||
Table: "auth_emails",
|
Table: "emails",
|
||||||
},
|
},
|
||||||
ControlEntityType: {
|
ControlEntityType: {
|
||||||
Model: "Control",
|
Model: "Control",
|
||||||
@@ -234,11 +234,11 @@ var entityRegistry = map[uint16]EntityInfo{
|
|||||||
},
|
},
|
||||||
InvitationEntityType: {
|
InvitationEntityType: {
|
||||||
Model: "Invitation",
|
Model: "Invitation",
|
||||||
Table: "authz_invitations",
|
Table: "iam_invitations",
|
||||||
},
|
},
|
||||||
MembershipEntityType: {
|
MembershipEntityType: {
|
||||||
Model: "Membership",
|
Model: "Membership",
|
||||||
Table: "authz_memberships",
|
Table: "iam_memberships",
|
||||||
},
|
},
|
||||||
SlackMessageEntityType: {
|
SlackMessageEntityType: {
|
||||||
Model: "SlackMessage",
|
Model: "SlackMessage",
|
||||||
@@ -250,15 +250,15 @@ var entityRegistry = map[uint16]EntityInfo{
|
|||||||
},
|
},
|
||||||
SAMLConfigurationEntityType: {
|
SAMLConfigurationEntityType: {
|
||||||
Model: "SAMLConfiguration",
|
Model: "SAMLConfiguration",
|
||||||
Table: "auth_saml_configurations",
|
Table: "iam_saml_configurations",
|
||||||
},
|
},
|
||||||
PersonalAPIKeyEntityType: {
|
PersonalAPIKeyEntityType: {
|
||||||
Model: "PersonalAPIKey",
|
Model: "PersonalAPIKey",
|
||||||
Table: "auth_personal_api_keys",
|
Table: "iam_personal_api_keys",
|
||||||
},
|
},
|
||||||
PersonalAPIKeyMembershipEntityType: {
|
PersonalAPIKeyMembershipEntityType: {
|
||||||
Model: "PersonalAPIKeyMembership",
|
Model: "PersonalAPIKeyMembership",
|
||||||
Table: "authz_api_keys_memberships",
|
Table: "iam_personal_api_key_memberships",
|
||||||
},
|
},
|
||||||
MeetingEntityType: {
|
MeetingEntityType: {
|
||||||
Model: "Meeting",
|
Model: "Meeting",
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ FROM
|
|||||||
identities
|
identities
|
||||||
WHERE
|
WHERE
|
||||||
id IN (
|
id IN (
|
||||||
SELECT identity_id FROM authz_memberships WHERE organization_id = @organization_id
|
SELECT identity_id FROM iam_memberships WHERE organization_id = @organization_id
|
||||||
)
|
)
|
||||||
AND %s
|
AND %s
|
||||||
`
|
`
|
||||||
@@ -111,7 +111,7 @@ FROM
|
|||||||
identities
|
identities
|
||||||
WHERE
|
WHERE
|
||||||
id IN (
|
id IN (
|
||||||
SELECT identity_id FROM authz_memberships WHERE organization_id = @organization_id AND %s
|
SELECT identity_id FROM iam_memberships WHERE organization_id = @organization_id AND %s
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ func (i *Identity) CountMemberships(
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func (i Invitation) CursorKey(orderBy InvitationOrderField) page.CursorKey {
|
|||||||
func (i *Invitation) Insert(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
func (i *Invitation) Insert(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
authz_invitations (
|
iam_invitations (
|
||||||
tenant_id,
|
tenant_id,
|
||||||
id,
|
id,
|
||||||
organization_id,
|
organization_id,
|
||||||
@@ -133,7 +133,7 @@ SELECT
|
|||||||
accepted_at,
|
accepted_at,
|
||||||
created_at
|
created_at
|
||||||
FROM
|
FROM
|
||||||
authz_invitations
|
iam_invitations
|
||||||
WHERE
|
WHERE
|
||||||
id = @id
|
id = @id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -167,7 +167,7 @@ WHERE
|
|||||||
func (i *Invitation) Update(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
func (i *Invitation) Update(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
||||||
query := `
|
query := `
|
||||||
UPDATE
|
UPDATE
|
||||||
authz_invitations
|
iam_invitations
|
||||||
SET
|
SET
|
||||||
accepted_at = @accepted_at
|
accepted_at = @accepted_at
|
||||||
WHERE
|
WHERE
|
||||||
@@ -198,7 +198,7 @@ WHERE
|
|||||||
func (i *Invitation) Delete(ctx context.Context, conn pg.Conn, scope Scoper, invitationID gid.GID) error {
|
func (i *Invitation) Delete(ctx context.Context, conn pg.Conn, scope Scoper, invitationID gid.GID) error {
|
||||||
query := `
|
query := `
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
authz_invitations
|
iam_invitations
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @invitation_id
|
AND id = @invitation_id
|
||||||
@@ -247,7 +247,7 @@ SELECT
|
|||||||
accepted_at,
|
accepted_at,
|
||||||
created_at
|
created_at
|
||||||
FROM
|
FROM
|
||||||
authz_invitations
|
iam_invitations
|
||||||
WHERE
|
WHERE
|
||||||
email = @email
|
email = @email
|
||||||
AND %s
|
AND %s
|
||||||
@@ -300,7 +300,7 @@ SELECT
|
|||||||
accepted_at,
|
accepted_at,
|
||||||
created_at
|
created_at
|
||||||
FROM
|
FROM
|
||||||
authz_invitations
|
iam_invitations
|
||||||
WHERE
|
WHERE
|
||||||
organization_id = @organization_id
|
organization_id = @organization_id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -342,7 +342,7 @@ func (i *Invitations) CountByOrganizationID(
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
authz_invitations
|
iam_invitations
|
||||||
WHERE
|
WHERE
|
||||||
organization_id = @organization_id AND %s AND %s
|
organization_id = @organization_id AND %s AND %s
|
||||||
`
|
`
|
||||||
@@ -378,7 +378,7 @@ func (i *Invitations) CountByEmail(
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
authz_invitations
|
iam_invitations
|
||||||
WHERE
|
WHERE
|
||||||
email = @email
|
email = @email
|
||||||
AND %s
|
AND %s
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
@@ -102,7 +102,7 @@ WHERE
|
|||||||
func (m *Membership) Insert(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
func (m *Membership) Insert(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
authz_memberships (
|
iam_memberships (
|
||||||
tenant_id,
|
tenant_id,
|
||||||
id,
|
id,
|
||||||
identity_id,
|
identity_id,
|
||||||
@@ -165,7 +165,7 @@ WITH mbr AS (
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
id = @membership_id
|
id = @membership_id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -244,7 +244,7 @@ SELECT
|
|||||||
m.created_at,
|
m.created_at,
|
||||||
m.updated_at
|
m.updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_memberships m
|
iam_memberships m
|
||||||
INNER JOIN %s e ON e.id = @entity_id
|
INNER JOIN %s e ON e.id = @entity_id
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
@@ -304,7 +304,7 @@ WITH mbr AS (
|
|||||||
am.created_at,
|
am.created_at,
|
||||||
am.updated_at
|
am.updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_memberships am
|
iam_memberships am
|
||||||
WHERE
|
WHERE
|
||||||
am.identity_id = @identity_id
|
am.identity_id = @identity_id
|
||||||
AND am.organization_id = @organization_id
|
AND am.organization_id = @organization_id
|
||||||
@@ -354,7 +354,7 @@ JOIN
|
|||||||
func (m *Membership) Update(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
func (m *Membership) Update(ctx context.Context, conn pg.Conn, scope Scoper) error {
|
||||||
query := `
|
query := `
|
||||||
UPDATE
|
UPDATE
|
||||||
authz_memberships
|
iam_memberships
|
||||||
SET
|
SET
|
||||||
role = @role,
|
role = @role,
|
||||||
updated_at = @updated_at
|
updated_at = @updated_at
|
||||||
@@ -387,7 +387,7 @@ WHERE
|
|||||||
func (m *Membership) Delete(ctx context.Context, conn pg.Conn, scope Scoper, membershipID gid.GID) error {
|
func (m *Membership) Delete(ctx context.Context, conn pg.Conn, scope Scoper, membershipID gid.GID) error {
|
||||||
query := `
|
query := `
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @membership_id
|
AND id = @membership_id
|
||||||
@@ -429,7 +429,7 @@ WITH mbr AS (
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -491,7 +491,7 @@ WITH mbr AS (
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
organization_id = @organization_id
|
organization_id = @organization_id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -555,7 +555,7 @@ func (m *Memberships) CountByOrganizationID(
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
organization_id = @organization_id
|
organization_id = @organization_id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -582,7 +582,7 @@ func (m *Memberships) CountByIdentityID(
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ ALTER TABLE users RENAME TO identities;
|
|||||||
ALTER TABLE sessions RENAME COLUMN user_id TO identity_id;
|
ALTER TABLE sessions RENAME COLUMN user_id TO identity_id;
|
||||||
ALTER TABLE authz_memberships RENAME COLUMN user_id TO identity_id;
|
ALTER TABLE authz_memberships RENAME COLUMN user_id TO identity_id;
|
||||||
ALTER TABLE peoples RENAME COLUMN user_id TO identity_id;
|
ALTER TABLE peoples RENAME COLUMN user_id TO identity_id;
|
||||||
ALTER TABLE auth_user_api_keys RENAME TO auth_personal_api_keys;
|
ALTER TABLE auth_user_api_keys RENAME COLUMN user_id TO identity_id;
|
||||||
ALTER TABLE auth_personal_api_keys RENAME COLUMN user_id TO identity_id;
|
ALTER TABLE authz_api_keys_memberships RENAME COLUMN auth_user_api_key_id TO personal_api_key_id;
|
||||||
ALTER TABLE authz_api_keys_memberships RENAME COLUMN auth_user_api_key_id TO auth_personal_api_key_id;
|
ALTER TABLE sessions RENAME TO iam_sessions;
|
||||||
|
ALTER TABLE authz_memberships RENAME TO iam_memberships;
|
||||||
|
ALTER TABLE authz_invitations RENAME TO iam_invitations;
|
||||||
|
ALTER TABLE auth_user_api_keys RENAME TO iam_personal_api_keys;
|
||||||
|
ALTER TABLE authz_api_keys_memberships RENAME TO iam_personal_api_key_memberships;
|
||||||
|
ALTER TABLE auth_saml_configurations RENAME TO iam_saml_configurations;
|
||||||
|
ALTER TABLE auth_saml_assertions RENAME TO iam_saml_assertions;
|
||||||
|
ALTER TABLE auth_saml_requests RENAME TO iam_saml_requests;
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ WITH identity_org AS (
|
|||||||
SELECT
|
SELECT
|
||||||
organization_id
|
organization_id
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
)
|
)
|
||||||
@@ -179,7 +179,7 @@ WITH identity_org AS (
|
|||||||
SELECT
|
SELECT
|
||||||
organization_id
|
organization_id
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
)
|
)
|
||||||
@@ -232,7 +232,7 @@ WITH identity_org AS (
|
|||||||
SELECT
|
SELECT
|
||||||
organization_id
|
organization_id
|
||||||
FROM
|
FROM
|
||||||
authz_memberships
|
iam_memberships
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
AND role = @role
|
AND role = @role
|
||||||
@@ -288,11 +288,11 @@ WITH personal_api_key_org AS (
|
|||||||
SELECT
|
SELECT
|
||||||
am.organization_id
|
am.organization_id
|
||||||
FROM
|
FROM
|
||||||
authz_api_keys_memberships akm
|
iam_personal_api_key_memberships akm
|
||||||
INNER JOIN
|
INNER JOIN
|
||||||
authz_memberships am ON akm.membership_id = am.id
|
iam_memberships am ON akm.membership_id = am.id
|
||||||
WHERE
|
WHERE
|
||||||
akm.auth_personal_api_key_id = @auth_personal_api_key_id
|
akm.personal_api_key_id = @personal_api_key_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
tenant_id,
|
tenant_id,
|
||||||
@@ -315,7 +315,7 @@ ORDER BY
|
|||||||
name ASC
|
name ASC
|
||||||
`
|
`
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"auth_personal_api_key_id": personalAPIKeyID}
|
args := pgx.StrictNamedArgs{"personal_api_key_id": personalAPIKeyID}
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_personal_api_keys
|
iam_personal_api_keys
|
||||||
WHERE
|
WHERE
|
||||||
id = @api_key_id
|
id = @api_key_id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
@@ -106,7 +106,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_personal_api_keys
|
iam_personal_api_keys
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
ORDER BY created_at DESC;
|
ORDER BY created_at DESC;
|
||||||
@@ -134,7 +134,7 @@ func (a *PersonalAPIKeys) CountByIdentityID(ctx context.Context, conn pg.Conn, i
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
auth_personal_api_keys
|
iam_personal_api_keys
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
ORDER BY created_at DESC;
|
ORDER BY created_at DESC;
|
||||||
@@ -156,7 +156,7 @@ func (a *PersonalAPIKey) Insert(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
auth_personal_api_keys (id, identity_id, name, expires_at, expire_reason, created_at, updated_at)
|
iam_personal_api_keys (id, identity_id, name, expires_at, expire_reason, created_at, updated_at)
|
||||||
VALUES (
|
VALUES (
|
||||||
@api_key_id,
|
@api_key_id,
|
||||||
@identity_id,
|
@identity_id,
|
||||||
@@ -192,7 +192,7 @@ func (a *PersonalAPIKey) Update(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
UPDATE
|
UPDATE
|
||||||
auth_personal_api_keys
|
iam_personal_api_keys
|
||||||
SET
|
SET
|
||||||
name = @name,
|
name = @name,
|
||||||
expires_at = @expires_at,
|
expires_at = @expires_at,
|
||||||
@@ -224,7 +224,7 @@ func (a *PersonalAPIKey) Delete(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
auth_personal_api_keys
|
iam_personal_api_keys
|
||||||
WHERE
|
WHERE
|
||||||
id = @api_key_id
|
id = @api_key_id
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (s *SAMLAssertion) Insert(
|
|||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
) error {
|
) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO auth_saml_assertions (id, organization_id, used_at, expires_at)
|
INSERT INTO iam_saml_assertions (id, organization_id, used_at, expires_at)
|
||||||
VALUES (@id, @organization_id, @used_at, @expires_at)
|
VALUES (@id, @organization_id, @used_at, @expires_at)
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ VALUES (@id, @organization_id, @used_at, @expires_at)
|
|||||||
_, err := conn.Exec(ctx, query, args)
|
_, err := conn.Exec(ctx, query, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var pgErr *pgconn.PgError
|
var pgErr *pgconn.PgError
|
||||||
if errors.As(err, &pgErr) && pgErr.Code == "23505" && pgErr.ConstraintName == "auth_saml_assertions_pkey" {
|
if errors.As(err, &pgErr) && pgErr.Code == "23505" && pgErr.ConstraintName == "iam_saml_assertions_pkey" {
|
||||||
return ErrResourceAlreadyExists
|
return ErrResourceAlreadyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ VALUES (@id, @organization_id, @used_at, @expires_at)
|
|||||||
|
|
||||||
func DeleteExpiredSAMLAssertions(ctx context.Context, conn pg.Conn, now time.Time) (int64, error) {
|
func DeleteExpiredSAMLAssertions(ctx context.Context, conn pg.Conn, now time.Time) (int64, error) {
|
||||||
query := `
|
query := `
|
||||||
DELETE FROM auth_saml_assertions
|
DELETE FROM iam_saml_assertions
|
||||||
WHERE expires_at < @now
|
WHERE expires_at < @now
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_saml_configurations
|
iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
@@ -120,7 +120,7 @@ LIMIT 1;
|
|||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query auth_saml_configurations: %w", err)
|
return fmt.Errorf("cannot query iam_saml_configurations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[SAMLConfiguration])
|
config, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[SAMLConfiguration])
|
||||||
@@ -159,7 +159,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_saml_configurations
|
iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @id
|
AND id = @id
|
||||||
@@ -173,7 +173,7 @@ LIMIT 1;
|
|||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query auth_saml_configurations: %w", err)
|
return fmt.Errorf("cannot query iam_saml_configurations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[SAMLConfiguration])
|
config, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[SAMLConfiguration])
|
||||||
@@ -215,7 +215,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_saml_configurations
|
iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
id = @id
|
id = @id
|
||||||
FOR UPDATE SKIP LOCKED;
|
FOR UPDATE SKIP LOCKED;
|
||||||
@@ -225,7 +225,7 @@ FOR UPDATE SKIP LOCKED;
|
|||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query auth_saml_configurations: %w", err)
|
return fmt.Errorf("cannot query iam_saml_configurations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[SAMLConfiguration])
|
config, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[SAMLConfiguration])
|
||||||
@@ -248,7 +248,7 @@ func (s *SAMLConfiguration) Insert(
|
|||||||
scope Scoper,
|
scope Scoper,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO auth_saml_configurations (
|
INSERT INTO iam_saml_configurations (
|
||||||
id,
|
id,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
organization_id,
|
organization_id,
|
||||||
@@ -324,7 +324,7 @@ func (s *SAMLConfiguration) Update(
|
|||||||
scope Scoper,
|
scope Scoper,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
UPDATE auth_saml_configurations
|
UPDATE iam_saml_configurations
|
||||||
SET
|
SET
|
||||||
enforcement_policy = @enforcement_policy,
|
enforcement_policy = @enforcement_policy,
|
||||||
idp_entity_id = @idp_entity_id,
|
idp_entity_id = @idp_entity_id,
|
||||||
@@ -379,7 +379,7 @@ func (s *SAMLConfiguration) Delete(
|
|||||||
scope Scoper,
|
scope Scoper,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
DELETE FROM auth_saml_configurations
|
DELETE FROM iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @id
|
AND id = @id
|
||||||
@@ -424,7 +424,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_saml_configurations
|
iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
@@ -438,7 +438,7 @@ ORDER BY email_domain ASC;
|
|||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query auth_saml_configurations: %w", err)
|
return fmt.Errorf("cannot query iam_saml_configurations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
samlConfigurations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[SAMLConfiguration])
|
samlConfigurations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[SAMLConfiguration])
|
||||||
@@ -461,7 +461,7 @@ func (s *SAMLConfigurations) CountByOrganizationID(
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
auth_saml_configurations
|
iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
@@ -474,7 +474,7 @@ WHERE
|
|||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("cannot query auth_saml_configurations: %w", err)
|
return 0, fmt.Errorf("cannot query iam_saml_configurations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
@@ -510,7 +510,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
auth_saml_configurations
|
iam_saml_configurations
|
||||||
WHERE
|
WHERE
|
||||||
domain_verified_at IS NULL
|
domain_verified_at IS NULL
|
||||||
AND domain_verification_token IS NOT NULL
|
AND domain_verification_token IS NOT NULL
|
||||||
@@ -520,7 +520,7 @@ LIMIT 100;
|
|||||||
|
|
||||||
rows, err := conn.Query(ctx, q)
|
rows, err := conn.Query(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query unverified auth_saml_configurations: %w", err)
|
return fmt.Errorf("cannot query unverified iam_saml_configurations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configs, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[SAMLConfiguration])
|
configs, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[SAMLConfiguration])
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (s *SAMLRequest) Insert(
|
|||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
) error {
|
) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO auth_saml_requests (id, organization_id, created_at, expires_at)
|
INSERT INTO iam_saml_requests (id, organization_id, created_at, expires_at)
|
||||||
VALUES (@id, @organization_id, @created_at, @expires_at)
|
VALUES (@id, @organization_id, @created_at, @expires_at)
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ func (s *SAMLRequest) Load(
|
|||||||
) error {
|
) error {
|
||||||
query := `
|
query := `
|
||||||
SELECT id, organization_id, created_at, expires_at
|
SELECT id, organization_id, created_at, expires_at
|
||||||
FROM auth_saml_requests
|
FROM iam_saml_requests
|
||||||
WHERE id = @id AND organization_id = @organization_id
|
WHERE id = @id AND organization_id = @organization_id
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`
|
`
|
||||||
@@ -100,7 +100,7 @@ func (s *SAMLRequest) Delete(
|
|||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
) error {
|
) error {
|
||||||
query := `
|
query := `
|
||||||
DELETE FROM auth_saml_requests
|
DELETE FROM iam_saml_requests
|
||||||
WHERE id = @id
|
WHERE id = @id
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ func LoadValidRequestIDsForOrganization(
|
|||||||
) ([]string, error) {
|
) ([]string, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM auth_saml_requests
|
FROM iam_saml_requests
|
||||||
WHERE organization_id = @organization_id AND expires_at > @now
|
WHERE organization_id = @organization_id AND expires_at > @now
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ WHERE organization_id = @organization_id AND expires_at > @now
|
|||||||
|
|
||||||
func DeleteExpiredSAMLRequests(ctx context.Context, conn pg.Conn, now time.Time) (int64, error) {
|
func DeleteExpiredSAMLRequests(ctx context.Context, conn pg.Conn, now time.Time) (int64, error) {
|
||||||
query := `
|
query := `
|
||||||
DELETE FROM auth_saml_requests
|
DELETE FROM iam_saml_requests
|
||||||
WHERE expires_at < @now
|
WHERE expires_at < @now
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
sessions
|
iam_sessions
|
||||||
WHERE
|
WHERE
|
||||||
id = @session_id
|
id = @session_id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
@@ -146,7 +146,7 @@ func (s *Session) Insert(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
sessions (id, identity_id, tenant_id, membership_id, data, parent_session_id, auth_method, authenticated_at, expire_reason, user_agent, ip_address, expired_at, created_at, updated_at)
|
iam_sessions (id, identity_id, tenant_id, membership_id, data, parent_session_id, auth_method, authenticated_at, expire_reason, user_agent, ip_address, expired_at, created_at, updated_at)
|
||||||
VALUES (
|
VALUES (
|
||||||
@session_id,
|
@session_id,
|
||||||
@identity_id,
|
@identity_id,
|
||||||
@@ -191,7 +191,7 @@ func (s *Session) Update(
|
|||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
UPDATE sessions
|
UPDATE iam_sessions
|
||||||
SET
|
SET
|
||||||
expired_at = @expired_at,
|
expired_at = @expired_at,
|
||||||
updated_at = @updated_at,
|
updated_at = @updated_at,
|
||||||
@@ -243,7 +243,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
sessions
|
iam_sessions
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
AND %s
|
AND %s
|
||||||
@@ -274,7 +274,7 @@ func (s *Sessions) CountByIdentityID(ctx context.Context, conn pg.Conn, identity
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
sessions
|
iam_sessions
|
||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
`
|
`
|
||||||
@@ -293,7 +293,7 @@ WHERE
|
|||||||
|
|
||||||
func (s *Sessions) ExpireAllForIdentityExceptOneSession(ctx context.Context, conn pg.Conn, identityID gid.GID, sessionID gid.GID) (int64, error) {
|
func (s *Sessions) ExpireAllForIdentityExceptOneSession(ctx context.Context, conn pg.Conn, identityID gid.GID, sessionID gid.GID) (int64, error) {
|
||||||
q := `
|
q := `
|
||||||
UPDATE sessions
|
UPDATE iam_sessions
|
||||||
SET
|
SET
|
||||||
expired_at = NOW(),
|
expired_at = NOW(),
|
||||||
updated_at = NOW(),
|
updated_at = NOW(),
|
||||||
@@ -335,7 +335,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
sessions
|
iam_sessions
|
||||||
WHERE
|
WHERE
|
||||||
parent_session_id = @root_session_id
|
parent_session_id = @root_session_id
|
||||||
AND membership_id = @membership_id
|
AND membership_id = @membership_id
|
||||||
|
|||||||
Reference in New Issue
Block a user