File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,16 @@ CREATE TABLE IF NOT EXISTS api_keys (
1111 metadata JSONB DEFAULT ' {}' ::jsonb,
1212 deleted_at TIMESTAMPTZ DEFAULT NULL ,
1313 CONSTRAINT pk_api_keys PRIMARY KEY (developer_id, api_key_id),
14- CONSTRAINT uq_api_keys_unique UNIQUE(developer_id, name) WHERE deleted_at IS NULL ,
1514 CONSTRAINT ct_api_keys_metadata_is_object CHECK (jsonb_typeof(metadata) = ' object' ),
1615 CONSTRAINT ct_api_keys_name_valid_identifier CHECK (name ~ ' ^[a-zA-Z][a-zA-Z0-9_]*$' ),
1716 CONSTRAINT fk_api_keys_developer FOREIGN KEY (developer_id) REFERENCES developers(developer_id)
1817);
1918
19+ -- Create partial unique index instead of constraint with WHERE clause
20+ CREATE UNIQUE INDEX IF NOT EXISTS uq_api_keys_developer_id_name
21+ ON api_keys (developer_id, name)
22+ WHERE deleted_at IS NULL ;
23+
2024-- Create trigger function for updated_at
2125CREATE OR REPLACE FUNCTION update_api_keys_timestamp ()
2226RETURNS TRIGGER AS $$
@@ -67,4 +71,4 @@ $$ LANGUAGE plpgsql SECURITY DEFINER;
6771-- Add comment to table
6872COMMENT ON TABLE api_keys IS ' Stores API keys with encryption for developers' ;
6973
70- COMMIT ;
74+ COMMIT ;
You can’t perform that action at this time.
0 commit comments