Skip to content

Commit dc8a65e

Browse files
committed
chore: add missing data dump script
1 parent 62c083f commit dc8a65e

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

cmd/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var (
100100

101101
dbDumpCmd = &cobra.Command{
102102
Use: "dump",
103-
Short: "Dumps data/schemas from the remote database",
103+
Short: "Dumps data or schemas from the remote database",
104104
RunE: func(cmd *cobra.Command, args []string) error {
105105
fsys := afero.NewOsFs()
106106
if err := loadLinkedProject(fsys); err != nil {

internal/db/dump/dump.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import (
1515
var (
1616
//go:embed templates/dump_schema.sh
1717
dumpSchemaScript string
18-
//go:embed templates/dump_schema.sh
18+
//go:embed templates/dump_data.sh
1919
dumpDataScript string
2020
)
2121

2222
func Run(ctx context.Context, path, username, password, database, host string, dataOnly bool, fsys afero.Fs) error {
23-
fmt.Fprintln(os.Stderr, "Dumping schemas from remote database...")
24-
script := dumpSchemaScript
23+
var script string
2524
if dataOnly {
25+
fmt.Fprintln(os.Stderr, "Dumping data from remote database...")
2626
script = dumpDataScript
27+
} else {
28+
fmt.Fprintln(os.Stderr, "Dumping schemas from remote database...")
29+
script = dumpSchemaScript
2730
}
2831
out, err := utils.DockerRunOnce(ctx, utils.Pg15Image, []string{
2932
"PGHOST=" + host,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Explanation of pg_dump flags:
5+
#
6+
# --exclude-schema omit data from internal schemas as they are maintained by platform
7+
# --schema '*' include all other schemas by default
8+
pg_dump \
9+
--data-only \
10+
--column-inserts \
11+
--quote-all-identifier \
12+
--exclude-schema "$EXCLUDED_SCHEMAS" \
13+
--schema '*' \
14+
--dbname "$DB_URL"
15+
16+
# Reset session config generated by pg_dump
17+
echo "RESET ALL;"

0 commit comments

Comments
 (0)