mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 15:37:33 +00:00
chore(db): refactoring instance+org tables to not use deleted_at (#10270)
This commit is contained in:
@@ -9,16 +9,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
ID string `json:"id,omitempty" db:"id"`
|
ID string `json:"id,omitempty" db:"id"`
|
||||||
Name string `json:"name,omitempty" db:"name"`
|
Name string `json:"name,omitempty" db:"name"`
|
||||||
DefaultOrgID string `json:"defaultOrgId,omitempty" db:"default_org_id"`
|
DefaultOrgID string `json:"defaultOrgId,omitempty" db:"default_org_id"`
|
||||||
IAMProjectID string `json:"iamProjectId,omitempty" db:"iam_project_id"`
|
IAMProjectID string `json:"iamProjectId,omitempty" db:"iam_project_id"`
|
||||||
ConsoleClientID string `json:"consoleClientId,omitempty" db:"console_client_id"`
|
ConsoleClientID string `json:"consoleClientId,omitempty" db:"console_client_id"`
|
||||||
ConsoleAppID string `json:"consoleAppId,omitempty" db:"console_app_id"`
|
ConsoleAppID string `json:"consoleAppId,omitempty" db:"console_app_id"`
|
||||||
DefaultLanguage string `json:"defaultLanguage,omitempty" db:"default_language"`
|
DefaultLanguage string `json:"defaultLanguage,omitempty" db:"default_language"`
|
||||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
||||||
DeletedAt *time.Time `json:"deletedAt" db:"deleted_at"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type instanceCacheIndex uint8
|
type instanceCacheIndex uint8
|
||||||
@@ -58,8 +57,6 @@ type instanceColumns interface {
|
|||||||
CreatedAtColumn() database.Column
|
CreatedAtColumn() database.Column
|
||||||
// UpdatedAtColumn returns the column for the updated at field.
|
// UpdatedAtColumn returns the column for the updated at field.
|
||||||
UpdatedAtColumn() database.Column
|
UpdatedAtColumn() database.Column
|
||||||
// DeletedAtColumn returns the column for the deleted at field.
|
|
||||||
DeletedAtColumn() database.Column
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// instanceConditions define all the conditions for the instance table.
|
// instanceConditions define all the conditions for the instance table.
|
||||||
|
@@ -16,13 +16,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Organization struct {
|
type Organization struct {
|
||||||
ID string `json:"id,omitempty" db:"id"`
|
ID string `json:"id,omitempty" db:"id"`
|
||||||
Name string `json:"name,omitempty" db:"name"`
|
Name string `json:"name,omitempty" db:"name"`
|
||||||
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
|
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
|
||||||
State string `json:"state,omitempty" db:"state"`
|
State string `json:"state,omitempty" db:"state"`
|
||||||
CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"`
|
CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"`
|
UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"`
|
||||||
DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrgIdentifierCondition is used to help specify a single Organization,
|
// OrgIdentifierCondition is used to help specify a single Organization,
|
||||||
@@ -46,8 +45,6 @@ type organizationColumns interface {
|
|||||||
CreatedAtColumn() database.Column
|
CreatedAtColumn() database.Column
|
||||||
// UpdatedAtColumn returns the column for the updated at field.
|
// UpdatedAtColumn returns the column for the updated at field.
|
||||||
UpdatedAtColumn() database.Column
|
UpdatedAtColumn() database.Column
|
||||||
// DeletedAtColumn returns the column for the deleted at field.
|
|
||||||
DeletedAtColumn() database.Column
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// organizationConditions define all the conditions for the instance table.
|
// organizationConditions define all the conditions for the instance table.
|
||||||
@@ -77,7 +74,7 @@ type OrganizationRepository interface {
|
|||||||
organizationChanges
|
organizationChanges
|
||||||
|
|
||||||
Get(ctx context.Context, id OrgIdentifierCondition, instance_id string, opts ...database.Condition) (*Organization, error)
|
Get(ctx context.Context, id OrgIdentifierCondition, instance_id string, opts ...database.Condition) (*Organization, error)
|
||||||
List(ctx context.Context, opts ...database.Condition) ([]*Organization, error)
|
List(ctx context.Context, conditions ...database.Condition) ([]*Organization, error)
|
||||||
|
|
||||||
Create(ctx context.Context, instance *Organization) error
|
Create(ctx context.Context, instance *Organization) error
|
||||||
Update(ctx context.Context, id OrgIdentifierCondition, instance_id string, changes ...database.Change) (int64, error)
|
Update(ctx context.Context, id OrgIdentifierCondition, instance_id string, changes ...database.Change) (int64, error)
|
||||||
|
@@ -7,8 +7,7 @@ CREATE TABLE IF NOT EXISTS zitadel.instances(
|
|||||||
console_app_id TEXT, -- NOT NULL,
|
console_app_id TEXT, -- NOT NULL,
|
||||||
default_language TEXT, -- NOT NULL,
|
default_language TEXT, -- NOT NULL,
|
||||||
created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
||||||
updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL
|
||||||
deleted_at TIMESTAMPTZ DEFAULT NULL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION zitadel.set_updated_at()
|
CREATE OR REPLACE FUNCTION zitadel.set_updated_at()
|
||||||
|
@@ -10,21 +10,12 @@ CREATE TABLE zitadel.organizations(
|
|||||||
state zitadel.organization_state NOT NULL,
|
state zitadel.organization_state NOT NULL,
|
||||||
created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
||||||
updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
||||||
deleted_at TIMESTAMPTZ DEFAULT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (instance_id, id)
|
PRIMARY KEY (instance_id, id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX org_unique_instance_id_name_idx
|
CREATE UNIQUE INDEX org_unique_instance_id_name_idx
|
||||||
ON zitadel.organizations (instance_id, name)
|
ON zitadel.organizations (instance_id, name);
|
||||||
WHERE deleted_at IS NULL;
|
|
||||||
|
|
||||||
-- users are able to set the id for organizations
|
|
||||||
CREATE INDEX org_id_not_deleted_idx ON zitadel.organizations (id)
|
|
||||||
WHERE deleted_at IS NULL;
|
|
||||||
|
|
||||||
CREATE INDEX org_name_not_deleted_idx ON zitadel.organizations (name)
|
|
||||||
WHERE deleted_at IS NULL;
|
|
||||||
|
|
||||||
CREATE TRIGGER trigger_set_updated_at
|
CREATE TRIGGER trigger_set_updated_at
|
||||||
BEFORE UPDATE ON zitadel.organizations
|
BEFORE UPDATE ON zitadel.organizations
|
||||||
|
@@ -54,7 +54,6 @@ func TestServer_TestInstanceReduces(t *testing.T) {
|
|||||||
assert.WithinRange(t, instance.CreatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, instance.CreatedAt, beforeCreate, afterCreate)
|
||||||
// event instance.added
|
// event instance.added
|
||||||
assert.WithinRange(t, instance.UpdatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, instance.UpdatedAt, beforeCreate, afterCreate)
|
||||||
assert.Nil(t, instance.DeletedAt)
|
|
||||||
}, retryDuration, tick)
|
}, retryDuration, tick)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -132,7 +131,7 @@ func TestServer_TestInstanceReduces(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// event instance.removed
|
// event instance.removed
|
||||||
assert.Nil(t, instance)
|
assert.Nil(t, instance)
|
||||||
require.NoError(t, err)
|
require.Equal(t, repository.ErrResourceDoesNotExist, err)
|
||||||
}, retryDuration, tick)
|
}, retryDuration, tick)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,6 @@ func TestServer_TestOrganizationReduces(t *testing.T) {
|
|||||||
assert.Equal(t, domain.OrgStateActive.String(), organization.State)
|
assert.Equal(t, domain.OrgStateActive.String(), organization.State)
|
||||||
assert.WithinRange(t, organization.CreatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, organization.CreatedAt, beforeCreate, afterCreate)
|
||||||
assert.WithinRange(t, organization.UpdatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, organization.UpdatedAt, beforeCreate, afterCreate)
|
||||||
assert.Nil(t, organization.DeletedAt)
|
|
||||||
}, retryDuration, tick)
|
}, retryDuration, tick)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -209,7 +208,7 @@ func TestServer_TestOrganizationReduces(t *testing.T) {
|
|||||||
orgRepo.NameCondition(orgName),
|
orgRepo.NameCondition(orgName),
|
||||||
instanceID,
|
instanceID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.Equal(t, repository.ErrResourceDoesNotExist, err)
|
||||||
|
|
||||||
// event org.remove
|
// event org.remove
|
||||||
assert.Nil(t, organization)
|
assert.Nil(t, organization)
|
||||||
|
@@ -3,7 +3,6 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5/pgconn"
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ func InstanceRepository(client database.QueryExecutor) domain.InstanceRepository
|
|||||||
// repository
|
// repository
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
const queryInstanceStmt = `SELECT id, name, default_org_id, iam_project_id, console_client_id, console_app_id, default_language, created_at, updated_at, deleted_at` +
|
const queryInstanceStmt = `SELECT id, name, default_org_id, iam_project_id, console_client_id, console_app_id, default_language, created_at, updated_at` +
|
||||||
` FROM zitadel.instances`
|
` FROM zitadel.instances`
|
||||||
|
|
||||||
// Get implements [domain.InstanceRepository].
|
// Get implements [domain.InstanceRepository].
|
||||||
@@ -39,23 +38,20 @@ func (i *instance) Get(ctx context.Context, id string) (*domain.Instance, error)
|
|||||||
builder.WriteString(queryInstanceStmt)
|
builder.WriteString(queryInstanceStmt)
|
||||||
|
|
||||||
idCondition := i.IDCondition(id)
|
idCondition := i.IDCondition(id)
|
||||||
// return only non deleted instances
|
writeCondition(&builder, idCondition)
|
||||||
conditions := []database.Condition{idCondition, database.IsNull(i.DeletedAtColumn())}
|
|
||||||
writeCondition(&builder, database.And(conditions...))
|
|
||||||
|
|
||||||
return scanInstance(ctx, i.client, &builder)
|
return scanInstance(ctx, i.client, &builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List implements [domain.InstanceRepository].
|
// List implements [domain.InstanceRepository].
|
||||||
func (i *instance) List(ctx context.Context, opts ...database.Condition) ([]*domain.Instance, error) {
|
func (i *instance) List(ctx context.Context, conditions ...database.Condition) ([]*domain.Instance, error) {
|
||||||
var builder database.StatementBuilder
|
var builder database.StatementBuilder
|
||||||
|
|
||||||
builder.WriteString(queryInstanceStmt)
|
builder.WriteString(queryInstanceStmt)
|
||||||
|
|
||||||
// return only non deleted instances
|
if conditions != nil {
|
||||||
opts = append(opts, database.IsNull(i.DeletedAtColumn()))
|
writeCondition(&builder, database.And(conditions...))
|
||||||
notDeletedCondition := database.And(opts...)
|
}
|
||||||
writeCondition(&builder, notDeletedCondition)
|
|
||||||
|
|
||||||
return scanInstances(ctx, i.client, &builder)
|
return scanInstances(ctx, i.client, &builder)
|
||||||
}
|
}
|
||||||
@@ -107,9 +103,7 @@ func (i instance) Update(ctx context.Context, id string, changes ...database.Cha
|
|||||||
database.Changes(changes).Write(&builder)
|
database.Changes(changes).Write(&builder)
|
||||||
|
|
||||||
idCondition := i.IDCondition(id)
|
idCondition := i.IDCondition(id)
|
||||||
// don't update deleted instances
|
writeCondition(&builder, idCondition)
|
||||||
conditions := []database.Condition{idCondition, database.IsNull(i.DeletedAtColumn())}
|
|
||||||
writeCondition(&builder, database.And(conditions...))
|
|
||||||
|
|
||||||
stmt := builder.String()
|
stmt := builder.String()
|
||||||
|
|
||||||
@@ -121,13 +115,10 @@ func (i instance) Update(ctx context.Context, id string, changes ...database.Cha
|
|||||||
func (i instance) Delete(ctx context.Context, id string) (int64, error) {
|
func (i instance) Delete(ctx context.Context, id string) (int64, error) {
|
||||||
var builder database.StatementBuilder
|
var builder database.StatementBuilder
|
||||||
|
|
||||||
builder.WriteString(`UPDATE zitadel.instances SET deleted_at = $1`)
|
builder.WriteString(`DELETE FROM zitadel.instances`)
|
||||||
builder.AppendArgs(time.Now())
|
|
||||||
|
|
||||||
// don't delete already deleted instance
|
|
||||||
idCondition := i.IDCondition(id)
|
idCondition := i.IDCondition(id)
|
||||||
conditions := []database.Condition{idCondition, database.IsNull(i.DeletedAtColumn())}
|
writeCondition(&builder, idCondition)
|
||||||
writeCondition(&builder, database.And(conditions...))
|
|
||||||
|
|
||||||
return i.client.Exec(ctx, builder.String(), builder.Args()...)
|
return i.client.Exec(ctx, builder.String(), builder.Args()...)
|
||||||
}
|
}
|
||||||
@@ -204,11 +195,6 @@ func (instance) UpdatedAtColumn() database.Column {
|
|||||||
return database.NewColumn("updated_at")
|
return database.NewColumn("updated_at")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletedAtColumn implements [domain.instanceColumns].
|
|
||||||
func (instance) DeletedAtColumn() database.Column {
|
|
||||||
return database.NewColumn("deleted_at")
|
|
||||||
}
|
|
||||||
|
|
||||||
func scanInstance(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Instance, error) {
|
func scanInstance(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Instance, error) {
|
||||||
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -185,7 +185,6 @@ func TestCreateInstance(t *testing.T) {
|
|||||||
assert.Equal(t, tt.instance.DefaultLanguage, instance.DefaultLanguage)
|
assert.Equal(t, tt.instance.DefaultLanguage, instance.DefaultLanguage)
|
||||||
assert.WithinRange(t, instance.CreatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, instance.CreatedAt, beforeCreate, afterCreate)
|
||||||
assert.WithinRange(t, instance.UpdatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, instance.UpdatedAt, beforeCreate, afterCreate)
|
||||||
assert.Nil(t, instance.DeletedAt)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +297,6 @@ func TestUpdateInstance(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, newName, instance.Name)
|
assert.Equal(t, newName, instance.Name)
|
||||||
assert.WithinRange(t, instance.UpdatedAt, beforeUpdate, afterUpdate)
|
assert.WithinRange(t, instance.UpdatedAt, beforeUpdate, afterUpdate)
|
||||||
assert.Nil(t, instance.DeletedAt)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,6 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5/pgconn"
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ func OrganizationRepository(client database.QueryExecutor) domain.OrganizationRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryOrganizationStmt = `SELECT id, name, instance_id, state, created_at, updated_at, deleted_at` +
|
const queryOrganizationStmt = `SELECT id, name, instance_id, state, created_at, updated_at` +
|
||||||
` FROM zitadel.organizations`
|
` FROM zitadel.organizations`
|
||||||
|
|
||||||
// Get implements [domain.OrganizationRepository].
|
// Get implements [domain.OrganizationRepository].
|
||||||
@@ -39,24 +38,22 @@ func (o *org) Get(ctx context.Context, id domain.OrgIdentifierCondition, instanc
|
|||||||
builder.WriteString(queryOrganizationStmt)
|
builder.WriteString(queryOrganizationStmt)
|
||||||
|
|
||||||
instanceIDCondition := o.InstanceIDCondition(instanceID)
|
instanceIDCondition := o.InstanceIDCondition(instanceID)
|
||||||
// don't update deleted organizations
|
|
||||||
nonDeletedOrgs := database.IsNull(o.DeletedAtColumn())
|
|
||||||
|
|
||||||
conditions = append(conditions, id, instanceIDCondition, nonDeletedOrgs)
|
conditions = append(conditions, id, instanceIDCondition)
|
||||||
writeCondition(&builder, database.And(conditions...))
|
writeCondition(&builder, database.And(conditions...))
|
||||||
|
|
||||||
return scanOrganization(ctx, o.client, &builder)
|
return scanOrganization(ctx, o.client, &builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List implements [domain.OrganizationRepository].
|
// List implements [domain.OrganizationRepository].
|
||||||
func (o *org) List(ctx context.Context, opts ...database.Condition) ([]*domain.Organization, error) {
|
func (o *org) List(ctx context.Context, conditions ...database.Condition) ([]*domain.Organization, error) {
|
||||||
builder := database.StatementBuilder{}
|
builder := database.StatementBuilder{}
|
||||||
|
|
||||||
builder.WriteString(queryOrganizationStmt)
|
builder.WriteString(queryOrganizationStmt)
|
||||||
|
|
||||||
// return only non deleted organizations
|
if conditions != nil {
|
||||||
opts = append(opts, database.IsNull(o.DeletedAtColumn()))
|
writeCondition(&builder, database.And(conditions...))
|
||||||
writeCondition(&builder, database.And(opts...))
|
}
|
||||||
|
|
||||||
orderBy := database.OrderBy(o.CreatedAtColumn())
|
orderBy := database.OrderBy(o.CreatedAtColumn())
|
||||||
orderBy.Write(&builder)
|
orderBy.Write(&builder)
|
||||||
@@ -122,10 +119,8 @@ func (o org) Update(ctx context.Context, id domain.OrgIdentifierCondition, insta
|
|||||||
builder.WriteString(`UPDATE zitadel.organizations SET `)
|
builder.WriteString(`UPDATE zitadel.organizations SET `)
|
||||||
|
|
||||||
instanceIDCondition := o.InstanceIDCondition(instanceID)
|
instanceIDCondition := o.InstanceIDCondition(instanceID)
|
||||||
// don't update deleted organizations
|
|
||||||
nonDeletedOrgs := database.IsNull(o.DeletedAtColumn())
|
|
||||||
|
|
||||||
conditions := []database.Condition{id, instanceIDCondition, nonDeletedOrgs}
|
conditions := []database.Condition{id, instanceIDCondition}
|
||||||
database.Changes(changes).Write(&builder)
|
database.Changes(changes).Write(&builder)
|
||||||
writeCondition(&builder, database.And(conditions...))
|
writeCondition(&builder, database.And(conditions...))
|
||||||
|
|
||||||
@@ -139,14 +134,11 @@ func (o org) Update(ctx context.Context, id domain.OrgIdentifierCondition, insta
|
|||||||
func (o org) Delete(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string) (int64, error) {
|
func (o org) Delete(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string) (int64, error) {
|
||||||
builder := database.StatementBuilder{}
|
builder := database.StatementBuilder{}
|
||||||
|
|
||||||
builder.WriteString(`UPDATE zitadel.organizations SET deleted_at = $1`)
|
builder.WriteString(`DELETE FROM zitadel.organizations`)
|
||||||
builder.AppendArgs(time.Now())
|
|
||||||
|
|
||||||
instanceIDCondition := o.InstanceIDCondition(instanceID)
|
instanceIDCondition := o.InstanceIDCondition(instanceID)
|
||||||
// don't update deleted organizations
|
|
||||||
nonDeletedOrgs := database.IsNull(o.DeletedAtColumn())
|
|
||||||
|
|
||||||
conditions := []database.Condition{id, instanceIDCondition, nonDeletedOrgs}
|
conditions := []database.Condition{id, instanceIDCondition}
|
||||||
writeCondition(&builder, database.And(conditions...))
|
writeCondition(&builder, database.And(conditions...))
|
||||||
|
|
||||||
return o.client.Exec(ctx, builder.String(), builder.Args()...)
|
return o.client.Exec(ctx, builder.String(), builder.Args()...)
|
||||||
@@ -224,11 +216,6 @@ func (org) UpdatedAtColumn() database.Column {
|
|||||||
return database.NewColumn("updated_at")
|
return database.NewColumn("updated_at")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletedAtColumn implements [domain.organizationColumns].
|
|
||||||
func (org) DeletedAtColumn() database.Column {
|
|
||||||
return database.NewColumn("deleted_at")
|
|
||||||
}
|
|
||||||
|
|
||||||
func scanOrganization(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Organization, error) {
|
func scanOrganization(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Organization, error) {
|
||||||
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -247,7 +247,6 @@ func TestCreateOrganization(t *testing.T) {
|
|||||||
assert.Equal(t, tt.organization.State, organization.State)
|
assert.Equal(t, tt.organization.State, organization.State)
|
||||||
assert.WithinRange(t, organization.CreatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, organization.CreatedAt, beforeCreate, afterCreate)
|
||||||
assert.WithinRange(t, organization.UpdatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, organization.UpdatedAt, beforeCreate, afterCreate)
|
||||||
assert.Nil(t, organization.DeletedAt)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,7 +399,6 @@ func TestUpdateOrganization(t *testing.T) {
|
|||||||
assert.Equal(t, createdOrg.Name, organization.Name)
|
assert.Equal(t, createdOrg.Name, organization.Name)
|
||||||
assert.Equal(t, createdOrg.State, organization.State)
|
assert.Equal(t, createdOrg.State, organization.State)
|
||||||
assert.WithinRange(t, organization.UpdatedAt, beforeUpdate, afterUpdate)
|
assert.WithinRange(t, organization.UpdatedAt, beforeUpdate, afterUpdate)
|
||||||
assert.Nil(t, organization.DeletedAt)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,11 +97,8 @@ func (p *instanceRelationalProjection) reduceInstanceDelete(event eventstore.Eve
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
|
||||||
}
|
}
|
||||||
return handler.NewUpdateStatement(
|
return handler.NewDeleteStatement(
|
||||||
e,
|
e,
|
||||||
[]handler.Column{
|
|
||||||
handler.NewCol(DeletedAt, e.CreationDate()),
|
|
||||||
},
|
|
||||||
[]handler.Condition{
|
[]handler.Condition{
|
||||||
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
},
|
},
|
||||||
|
@@ -171,12 +171,8 @@ func (p *orgRelationalProjection) reduceOrgRelationalRemoved(event eventstore.Ev
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "PROJE-DGm9g", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "PROJE-DGm9g", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||||
}
|
}
|
||||||
return handler.NewUpdateStatement(
|
return handler.NewDeleteStatement(
|
||||||
e,
|
e,
|
||||||
[]handler.Column{
|
|
||||||
handler.NewCol(UpdatedAt, e.CreationDate()),
|
|
||||||
handler.NewCol(DeletedAt, e.CreationDate()),
|
|
||||||
},
|
|
||||||
[]handler.Condition{
|
[]handler.Condition{
|
||||||
handler.NewCond(OrgColumnID, e.Aggregate().ID),
|
handler.NewCond(OrgColumnID, e.Aggregate().ID),
|
||||||
handler.NewCond(OrgColumnInstanceID, e.Aggregate().InstanceID),
|
handler.NewCond(OrgColumnInstanceID, e.Aggregate().InstanceID),
|
||||||
|
@@ -4,5 +4,4 @@ const (
|
|||||||
State = "state"
|
State = "state"
|
||||||
CreatedAt = "created_at"
|
CreatedAt = "created_at"
|
||||||
UpdatedAt = "updated_at"
|
UpdatedAt = "updated_at"
|
||||||
DeletedAt = "deleted_at"
|
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user