Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit 18f1617

Browse files
authored
Allow support for Table names in camel case (#147)
1 parent 3d992e3 commit 18f1617

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

fixtures/pg_simple.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ CREATE TABLE "order_items" (
2525
FOREIGN KEY (order_id) REFERENCES orders(id)
2626
);
2727

28+
CREATE TABLE "OrderItems" (
29+
id UUID PRIMARY KEY NOT NULL,
30+
order_id UUID NOT NULL,
31+
created_at timestamp,
32+
FOREIGN KEY (order_id) REFERENCES orders(id)
33+
);
2834

2935
CREATE VIEW "users_view" AS SELECT id, username FROM "users" WHERE active=true;
3036

pkg/dumper/postgres/dumper.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package postgres
33
import (
44
"database/sql"
55
"fmt"
6-
"strconv"
6+
"strings"
77

88
"github.com/lib/pq"
99
log "github.com/sirupsen/logrus"
@@ -85,7 +85,7 @@ func (d *pgDumper) PreDumpTables(tables []string) error {
8585
if !d.isRDS {
8686
log.Debug("Disabling triggers")
8787
for _, tbl := range tables {
88-
query := fmt.Sprintf("ALTER TABLE %s DISABLE TRIGGER ALL", strconv.Quote(tbl))
88+
query := fmt.Sprintf("ALTER TABLE %q DISABLE TRIGGER ALL", strings.Trim(tbl, "\""))
8989
if _, err := d.conn.Exec(query); err != nil {
9090
return fmt.Errorf("failed to disable triggers for %s: %w", tbl, err)
9191
}
@@ -111,9 +111,9 @@ func (d *pgDumper) PreDumpTables(tables []string) error {
111111
if err := rows.Scan(&fk.tableName, &fk.constraintName, &fk.constraintDefinition); err != nil {
112112
return fmt.Errorf("failed to load ForeignKeyInfo: %w", err)
113113
}
114-
query := fmt.Sprintf("ALTER TABLE %s DROP CONSTRAINT %s", strconv.Quote(fk.tableName), strconv.Quote(fk.constraintName))
114+
query := fmt.Sprintf("ALTER TABLE %q DROP CONSTRAINT %q", strings.Trim(fk.tableName, "\""), strings.Trim(fk.constraintName, "\""))
115115
if _, err := d.conn.Exec(query); err != nil {
116-
return fmt.Errorf("failed to frop contraint %s.%s: %w", fk.tableName, fk.constraintName, err)
116+
return fmt.Errorf("failed to drop constraint %s.%s: %w", fk.tableName, fk.constraintName, err)
117117
}
118118
d.foreignKeys = append(d.foreignKeys, fk)
119119
}
@@ -126,7 +126,7 @@ func (d *pgDumper) PostDumpTables(tables []string) error {
126126
if !d.isRDS {
127127
log.Debug("Reenabling triggers")
128128
for _, tbl := range tables {
129-
query := fmt.Sprintf("ALTER TABLE %s ENABLE TRIGGER ALL", strconv.Quote(tbl))
129+
query := fmt.Sprintf("ALTER TABLE %q ENABLE TRIGGER ALL", strings.Trim(tbl, "\""))
130130
if _, err := d.conn.Exec(query); err != nil {
131131
return fmt.Errorf("failed to enable triggers for %s: %w", tbl, err)
132132
}
@@ -136,7 +136,7 @@ func (d *pgDumper) PostDumpTables(tables []string) error {
136136

137137
log.Debug("Recreating foreign keys")
138138
for _, fk := range d.foreignKeys {
139-
query := fmt.Sprintf("ALTER TABLE %s ADD CONSTRAINT %s %s", strconv.Quote(fk.tableName), strconv.Quote(fk.constraintName), fk.constraintDefinition)
139+
query := fmt.Sprintf("ALTER TABLE %q ADD CONSTRAINT %q %s", strings.Trim(fk.tableName, "\""), strings.Trim(fk.constraintName, "\""), fk.constraintDefinition)
140140
if _, err := d.conn.Exec(query); err != nil {
141141
return fmt.Errorf("failed to re-create ForeignKey %s.%s: %w", fk.tableName, fk.constraintName, err)
142142
}

0 commit comments

Comments
 (0)