Skip to content

Commit 0e4c50e

Browse files
committed
test: print pg_dump output
1 parent c59cfea commit 0e4c50e

2 files changed

Lines changed: 11 additions & 39 deletions

File tree

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
--
2-
-- PostgreSQL database dump
3-
--
41

5-
-- Dumped from database version 15.12 (Homebrew)
6-
-- Dumped by pg_dump version 15.12 (Homebrew)
72

83
SET statement_timeout = 0;
94
SET lock_timeout = 0;
@@ -16,16 +11,10 @@ SET xmloption = content;
1611
SET client_min_messages = warning;
1712
SET row_security = off;
1813

19-
--
20-
-- Name: smp_server; Type: SCHEMA; Schema: -; Owner: -
21-
--
2214

2315
CREATE SCHEMA smp_server;
2416

2517

26-
--
27-
-- Name: migrations; Type: TABLE; Schema: smp_server; Owner: -
28-
--
2918

3019
CREATE TABLE smp_server.migrations (
3120
name text NOT NULL,
@@ -34,9 +23,6 @@ CREATE TABLE smp_server.migrations (
3423
);
3524

3625

37-
--
38-
-- Name: msg_queues; Type: TABLE; Schema: smp_server; Owner: -
39-
--
4026

4127
CREATE TABLE smp_server.msg_queues (
4228
recipient_id bytea NOT NULL,
@@ -57,51 +43,30 @@ CREATE TABLE smp_server.msg_queues (
5743
);
5844

5945

60-
--
61-
-- Name: migrations migrations_pkey; Type: CONSTRAINT; Schema: smp_server; Owner: -
62-
--
6346

6447
ALTER TABLE ONLY smp_server.migrations
6548
ADD CONSTRAINT migrations_pkey PRIMARY KEY (name);
6649

6750

68-
--
69-
-- Name: msg_queues msg_queues_pkey; Type: CONSTRAINT; Schema: smp_server; Owner: -
70-
--
7151

7252
ALTER TABLE ONLY smp_server.msg_queues
7353
ADD CONSTRAINT msg_queues_pkey PRIMARY KEY (recipient_id);
7454

7555

76-
--
77-
-- Name: idx_msg_queues_link_id; Type: INDEX; Schema: smp_server; Owner: -
78-
--
7956

8057
CREATE UNIQUE INDEX idx_msg_queues_link_id ON smp_server.msg_queues USING btree (link_id);
8158

8259

83-
--
84-
-- Name: idx_msg_queues_notifier_id; Type: INDEX; Schema: smp_server; Owner: -
85-
--
8660

8761
CREATE UNIQUE INDEX idx_msg_queues_notifier_id ON smp_server.msg_queues USING btree (notifier_id);
8862

8963

90-
--
91-
-- Name: idx_msg_queues_sender_id; Type: INDEX; Schema: smp_server; Owner: -
92-
--
9364

9465
CREATE UNIQUE INDEX idx_msg_queues_sender_id ON smp_server.msg_queues USING btree (sender_id);
9566

9667

97-
--
98-
-- Name: idx_msg_queues_updated_at; Type: INDEX; Schema: smp_server; Owner: -
99-
--
10068

10169
CREATE INDEX idx_msg_queues_updated_at ON smp_server.msg_queues USING btree (deleted_at, updated_at);
10270

10371

104-
--
105-
-- PostgreSQL database dump complete
106-
--
10772

tests/ServerTests/SchemaDump.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import Simplex.Messaging.Agent.Store.Shared (Migration (..), MigrationConfirmati
1616
import Simplex.Messaging.Server.QueueStore.Postgres.Migrations (serverMigrations)
1717
import Simplex.Messaging.Util (ifM)
1818
import System.Directory (doesFileExist, removeFile)
19-
import System.Process (readCreateProcess, shell)
19+
import System.Environment (lookupEnv)
20+
import System.Process (readCreateProcess, readCreateProcessWithExitCode, shell)
2021
import Test.Hspec
2122

2223
testDBSchema :: B.ByteString
@@ -39,8 +40,8 @@ testServerDBOpts =
3940

4041
serverSchemaDumpTest :: Spec
4142
serverSchemaDumpTest = do
42-
it "verify and overwrite schema dump" testVerifySchemaDump
43-
it "verify schema down migrations" testSchemaMigrations
43+
fit "verify and overwrite schema dump" testVerifySchemaDump
44+
fit "verify schema down migrations" testSchemaMigrations
4445

4546
testVerifySchemaDump :: IO ()
4647
testVerifySchemaDump = do
@@ -80,10 +81,16 @@ skipComparisonForDownMigrations =
8081

8182
getSchema :: FilePath -> IO String
8283
getSchema schemaPath = do
84+
ci <- (Just "true" ==) <$> lookupEnv "CI"
8385
let cmd =
8486
("pg_dump " <> B.unpack testServerDBConnstr <> " --schema " <> B.unpack testDBSchema)
8587
<> " --schema-only --no-comments --no-owner --no-privileges --no-acl --no-subscriptions --no-tablespaces --no-table-access-method > "
8688
<> schemaPath
87-
void $ readCreateProcess (shell cmd) ""
89+
(code, out, err) <- readCreateProcessWithExitCode (shell cmd) ""
90+
print code
91+
putStrLn $ "out: " <> out
92+
putStrLn $ "err: " <> err
93+
let sed = (if ci then "sed -i" else "sed -i ''")
94+
void $ readCreateProcess (shell $ sed <> " '/^--/d' " <> schemaPath) ""
8895
sch <- readFile schemaPath
8996
sch `deepseq` pure sch

0 commit comments

Comments
 (0)