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