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