Skip to content

Commit

Permalink
Merge pull request #28 from printeers/feature/retain-empty-lines
Browse files Browse the repository at this point in the history
Remove deletion of empty lines
DAAAAAAAAAAAAAAAAN authored Jan 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 5b1cc82 + 32919ba commit 22b8292
Showing 5 changed files with 20 additions and 23 deletions.
31 changes: 8 additions & 23 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -526,30 +526,15 @@ func generateMigrationStatements(
}

// Filter stuff from go-migrate that doesn't exist in the target db, and we don't have and need anyway
statements = strings.ReplaceAll(
statements,
"alter table \"public\".\"schema_migrations\" drop constraint \"schema_migrations_pkey\";",
"",
)
statements = strings.ReplaceAll(
statements,
"drop index if exists \"public\".\"schema_migrations_pkey\";",
"",
)
statements = strings.ReplaceAll(
statements,
"drop table \"public\".\"schema_migrations\";",
"",
)
statements = strings.Trim(statements, "\n")

var lines []string
for _, line := range strings.Split(statements, "\n") {
if line != "" {
lines = append(lines, line)
}
filter := []string{
"alter table \"public\".\"schema_migrations\" drop constraint \"schema_migrations_pkey\";\n\n",
"drop index if exists \"public\".\"schema_migrations_pkey\";\n\n",
"drop table \"public\".\"schema_migrations\";\n\n",
}
statements = strings.Join(lines, "\n")
for _, f := range filter {
statements = strings.ReplaceAll(statements, f, "")
}
statements = strings.Trim(statements, "\n")

extraStatements, err := generateMissingPermissionStatements(ctx, tmpDir, statements, targetConn, migrateConn)
if err != nil {
1 change: 1 addition & 0 deletions tests/output/migrations/002_schemas.up.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
create schema if not exists "factory";

create schema if not exists "warehouse";
2 changes: 2 additions & 0 deletions tests/output/migrations/003_tables.up.sql
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ create table "factory"."machines" (
"name" text not null,
"toys_produced" bigint not null
);


create table "warehouse"."storage_locations" (
"shelf" bigint not null,
"total_capacity" bigint not null,
7 changes: 7 additions & 0 deletions tests/output/migrations/004_sequences.up.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
create sequence "factory"."seq_machines_id";

create sequence "warehouse"."seq_storage_locations_id";

alter table "factory"."machines" add column "id" bigint not null default nextval('factory.seq_machines_id'::regclass);

alter table "warehouse"."storage_locations" add column "id" bigint not null default nextval('warehouse.seq_storage_locations_id'::regclass);

CREATE UNIQUE INDEX machines_pk ON factory.machines USING btree (id);

CREATE UNIQUE INDEX storage_locations_pk ON warehouse.storage_locations USING btree (id);

alter table "factory"."machines" add constraint "machines_pk" PRIMARY KEY using index "machines_pk";

alter table "warehouse"."storage_locations" add constraint "storage_locations_pk" PRIMARY KEY using index "storage_locations_pk";
2 changes: 2 additions & 0 deletions tests/output/migrations/006_triggers.up.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set check_function_bodies = off;

CREATE OR REPLACE FUNCTION factory.tr_machines_toys_produced_increase()
RETURNS trigger
LANGUAGE plpgsql
@@ -11,4 +12,5 @@ BEGIN
END;
$function$
;

CREATE TRIGGER toys_produced_increase BEFORE UPDATE OF toys_produced ON factory.machines FOR EACH ROW EXECUTE FUNCTION factory.tr_machines_toys_produced_increase();

0 comments on commit 22b8292

Please sign in to comment.