2022-03-28 08:05:09 +00:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-06 06:13:40 +00:00
|
|
|
"database/sql"
|
2024-01-25 16:28:20 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2022-04-06 06:13:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
createAssets = `
|
|
|
|
CREATE TABLE system.assets (
|
|
|
|
instance_id TEXT,
|
|
|
|
asset_type TEXT,
|
|
|
|
resource_owner TEXT,
|
|
|
|
name TEXT,
|
|
|
|
content_type TEXT,
|
2022-08-31 07:52:43 +00:00
|
|
|
hash TEXT GENERATED ALWAYS AS (md5(data)) STORED,
|
|
|
|
data BYTEA,
|
2022-04-06 06:13:40 +00:00
|
|
|
updated_at TIMESTAMPTZ,
|
2022-03-28 08:05:09 +00:00
|
|
|
|
2022-04-06 06:13:40 +00:00
|
|
|
PRIMARY KEY (instance_id, resource_owner, name)
|
|
|
|
);
|
|
|
|
`
|
2022-03-28 08:05:09 +00:00
|
|
|
)
|
|
|
|
|
2022-04-06 06:13:40 +00:00
|
|
|
type AssetTable struct {
|
|
|
|
dbClient *sql.DB
|
2022-03-28 08:05:09 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 16:28:20 +00:00
|
|
|
func (mig *AssetTable) Execute(ctx context.Context, _ eventstore.Event) error {
|
2022-04-06 06:13:40 +00:00
|
|
|
_, err := mig.dbClient.ExecContext(ctx, createAssets)
|
2022-03-28 08:05:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-06 06:13:40 +00:00
|
|
|
func (mig *AssetTable) String() string {
|
|
|
|
return "02_assets"
|
2022-03-28 08:05:09 +00:00
|
|
|
}
|