mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
fix: enable env vars in setup steps (and deprecate admin subcommand) (#3871)
* fix: enable env vars in setup steps (and deprecate admin subcommand) * fix tests and error text
This commit is contained in:
2
cmd/initialise/sql/01_user.sql
Normal file
2
cmd/initialise/sql/01_user.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- replace %[1]s with the name of the user
|
||||
CREATE USER %[1]s WITH PASSWORD $1
|
2
cmd/initialise/sql/02_database.sql
Normal file
2
cmd/initialise/sql/02_database.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- replace %[1]s with the name of the database
|
||||
CREATE DATABASE %[1]s
|
3
cmd/initialise/sql/03_grant_user.sql
Normal file
3
cmd/initialise/sql/03_grant_user.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- replace the first %[1]s with the database
|
||||
-- replace the second \%[2]s with the user
|
||||
GRANT ALL ON DATABASE %[1]s TO %[2]s
|
1
cmd/initialise/sql/04_eventstore.sql
Normal file
1
cmd/initialise/sql/04_eventstore.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA eventstore
|
1
cmd/initialise/sql/05_projections.sql
Normal file
1
cmd/initialise/sql/05_projections.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA projections
|
1
cmd/initialise/sql/06_system.sql
Normal file
1
cmd/initialise/sql/06_system.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA system;
|
6
cmd/initialise/sql/07_encryption_keys_table.sql
Normal file
6
cmd/initialise/sql/07_encryption_keys_table.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE system.encryption_keys (
|
||||
id TEXT NOT NULL
|
||||
, key TEXT NOT NULL
|
||||
|
||||
, PRIMARY KEY (id)
|
||||
);
|
1
cmd/initialise/sql/08_enable_hash_sharded_indexes.sql
Normal file
1
cmd/initialise/sql/08_enable_hash_sharded_indexes.sql
Normal file
@@ -0,0 +1 @@
|
||||
SET experimental_enable_hash_sharded_indexes = on
|
25
cmd/initialise/sql/09_events_table.sql
Normal file
25
cmd/initialise/sql/09_events_table.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE eventstore.events (
|
||||
id UUID DEFAULT gen_random_uuid()
|
||||
, event_type TEXT NOT NULL
|
||||
, aggregate_type TEXT NOT NULL
|
||||
, aggregate_id TEXT NOT NULL
|
||||
, aggregate_version TEXT NOT NULL
|
||||
, event_sequence BIGINT NOT NULL
|
||||
, previous_aggregate_sequence BIGINT
|
||||
, previous_aggregate_type_sequence INT8
|
||||
, creation_date TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
, event_data JSONB
|
||||
, editor_user TEXT NOT NULL
|
||||
, editor_service TEXT NOT NULL
|
||||
, resource_owner TEXT NOT NULL
|
||||
, instance_id TEXT NOT NULL
|
||||
|
||||
, PRIMARY KEY (event_sequence DESC, instance_id) USING HASH WITH BUCKET_COUNT = 10
|
||||
, INDEX agg_type_agg_id (aggregate_type, aggregate_id, instance_id)
|
||||
, INDEX agg_type (aggregate_type, instance_id)
|
||||
, INDEX agg_type_seq (aggregate_type, event_sequence DESC, instance_id)
|
||||
STORING (id, event_type, aggregate_id, aggregate_version, previous_aggregate_sequence, creation_date, event_data, editor_user, editor_service, resource_owner, previous_aggregate_type_sequence)
|
||||
, INDEX max_sequence (aggregate_type, aggregate_id, event_sequence DESC, instance_id)
|
||||
, CONSTRAINT previous_sequence_unique UNIQUE (previous_aggregate_sequence DESC, instance_id)
|
||||
, CONSTRAINT prev_agg_type_seq_unique UNIQUE(previous_aggregate_type_sequence, instance_id)
|
||||
)
|
1
cmd/initialise/sql/10_system_sequence.sql
Normal file
1
cmd/initialise/sql/10_system_sequence.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SEQUENCE eventstore.system_seq
|
6
cmd/initialise/sql/11_unique_constraints_table.sql
Normal file
6
cmd/initialise/sql/11_unique_constraints_table.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE eventstore.unique_constraints (
|
||||
instance_id TEXT,
|
||||
unique_type TEXT,
|
||||
unique_field TEXT,
|
||||
PRIMARY KEY (instance_id, unique_type, unique_field)
|
||||
)
|
16
cmd/initialise/sql/README.md
Normal file
16
cmd/initialise/sql/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# SQL initialisation
|
||||
|
||||
The sql-files in this folder initialize the ZITADEL database and user. These objects need to exist before ZITADEL is able to set and start up.
|
||||
|
||||
## files
|
||||
|
||||
- 01_user.sql: create the user zitadel uses to connect to the database
|
||||
- 02_database.sql: create the database for zitadel
|
||||
- 03_grant_user.sql: grants the user created before to have full access to its database. The user needs full access to the database because zitadel makes ddl/dml on runtime
|
||||
- 04_eventstore.sql: creates the schema needed for eventsourcing
|
||||
- 05_projections.sql: creates the schema needed to read the data
|
||||
- 06_system.sql: creates the schema needed for ZITADEL itself
|
||||
- 07_encryption_keys_table.sql: creates the table for encryption keys (for event data)
|
||||
- files 08_enable_hash_sharded_indexes.sql and 09_events_table.sql must run in the same session
|
||||
- 08_enable_hash_sharded_indexes.sql enables the [hash sharded index](https://www.cockroachlabs.com/docs/stable/hash-sharded-indexes.html) feature for this session
|
||||
- 09_events_table.sql creates the table for eventsourcing
|
Reference in New Issue
Block a user