refactor: relational organization projection to use repository (#11621)

- Transitioned from using `handler.Statements` to a repository pattern
for managing organization data in migrations.
- Introduced a new method to set the updated timestamp for
organizations.
- Updated the projection logic to utilize the repository for creating,
updating, and deleting organization records.
This commit is contained in:
Silvan
2026-03-05 14:55:42 +01:00
committed by GitHub
parent 90faf440f4
commit 07dbb48cc7
7 changed files with 155 additions and 105 deletions
@@ -39,14 +39,22 @@ func (p project) List(ctx context.Context, client database.QueryExecutor, opts .
return getMany[domain.Project](ctx, client, builder)
}
const insertProjectStmt = `INSERT INTO zitadel.projects(
instance_id, organization_id, id, name, state, should_assert_role, is_authorization_required, is_project_access_required, used_labeling_setting_owner
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING created_at, updated_at`
func (p project) Create(ctx context.Context, client database.QueryExecutor, project *domain.Project) error {
var (
builder database.StatementBuilder
createdAt, updatedAt any = database.DefaultInstruction, database.DefaultInstruction
)
if !project.CreatedAt.IsZero() {
createdAt = project.CreatedAt
}
if !project.UpdatedAt.IsZero() {
updatedAt = project.UpdatedAt
}
func (project) Create(ctx context.Context, client database.QueryExecutor, project *domain.Project) error {
builder := database.NewStatementBuilder(insertProjectStmt,
builder.WriteString("INSERT INTO ")
builder.WriteString(p.qualifiedTableName())
builder.WriteString("(instance_id, organization_id, id, name, state, should_assert_role, is_authorization_required, is_project_access_required, used_labeling_setting_owner, created_at, updated_at) VALUES (")
builder.WriteArgs(
project.InstanceID,
project.OrganizationID,
project.ID,
@@ -56,7 +64,11 @@ func (project) Create(ctx context.Context, client database.QueryExecutor, projec
project.IsAuthorizationRequired,
project.IsProjectAccessRequired,
project.UsedLabelingSettingOwner,
createdAt,
updatedAt,
)
builder.WriteString(`) RETURNING created_at, updated_at`)
return client.QueryRow(ctx, builder.String(), builder.Args()...).
Scan(&project.CreatedAt, &project.UpdatedAt)
}
@@ -141,7 +153,7 @@ func (p project) StateCondition(state domain.ProjectState) database.Condition {
// -------------------------------------------------------------
func (p project) qualifiedTableName() string {
return "zitadel." + p.unqualifiedTableName()
return "zitadel.projects"
}
func (project) unqualifiedTableName() string {