You need to sign in or sign up before continuing.
Draft: feat(engine): schema diff (#329)
Description
Schema difference in DLE:
- Generate schema difference between clone and its snapshot
- Add a new endpoint to DLE API that generates the schema difference -
GET /clone/diff/[CLONE_ID]
- Add a new command to CLI that generates the schema difference -
dblab clone schema-diff [CLONE_ID]
- Use a global configuration database name (or default if it is not set) when clone creates if the creation request does not specify it
- Build DLE image using multistage and without disabling CGO on alpine because of pg_query dependencies
- Create an independent CLI tool to compare DB schemas and generates its diff
Related issue
Examples
Generated schema diff
CREATE UNIQUE INDEX title_idx ON films (title);
DROP INDEX title_idx;
ALTER TABLE distributors
ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
ALTER TABLE distributors
ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address);
ALTER TABLE pgbench_accounts
ADD COLUMN test integer NOT NULL DEFAULT 0;
Optimized queries
CREATE UNIQUE INDEX CONCURRENTLY title_idx ON films USING btree (title);
DROP INDEX CONCURRENTLY title_idx;
BEGIN; ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5) NOT VALID; COMMIT;
BEGIN; ALTER TABLE distributors VALIDATE CONSTRAINT zipchk; COMMIT;
BEGIN; ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) NOT VALID; COMMIT;
BEGIN; ALTER TABLE distributors VALIDATE CONSTRAINT distfk; COMMIT;
BEGIN; ALTER TABLE pgbench_accounts ADD COLUMN test int; COMMIT;
BEGIN; ALTER TABLE pgbench_accounts ALTER COLUMN test SET DEFAULT 0; COMMIT;
DO $$
DECLARE
-- Choose your own batch size
batch_size int := 1000;
min_id bigint; max_id bigint;
BEGIN
-- Choose your own column as a unique identifier instead of "aid"
SELECT min(aid), max(aid) INTO min_id, max_id FROM pgbench_accounts;
FOR i IN min_id..max_id BY batch_size LOOP
UPDATE pgbench_accounts SET test = 0
WHERE aid >= i AND aid < i+batch_size;
COMMIT;
END LOOP;
END; $$;
BEGIN; ALTER pgbench_accounts ALTER COLUMN pgbench_accounts SET NOT NULL; COMMIT;
Checklist
-
the MR description has been reviewed -
this MR does NOT have text changes OR there are text changes and they have been reviewed -
this MR does NOT have API/CLI changes OR there are API/CLI changes and they have been reviewed -
this MR does NOT have UI changes OR there are UI changes and they have been reviewed
Closes #329
Edited by Artyom Kartasov