Skip to content

Commit a8b1bf6

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

2 files changed

Lines changed: 16 additions & 40 deletions

File tree

Lines changed: 2 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,12 @@ 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-
--
18+
SET default_table_access_method = heap;
19+
2920

3021
CREATE TABLE smp_server.migrations (
3122
name text NOT NULL,
@@ -34,9 +25,6 @@ CREATE TABLE smp_server.migrations (
3425
);
3526

3627

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

4129
CREATE TABLE smp_server.msg_queues (
4230
recipient_id bytea NOT NULL,
@@ -57,51 +45,30 @@ CREATE TABLE smp_server.msg_queues (
5745
);
5846

5947

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

6449
ALTER TABLE ONLY smp_server.migrations
6550
ADD CONSTRAINT migrations_pkey PRIMARY KEY (name);
6651

6752

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

7254
ALTER TABLE ONLY smp_server.msg_queues
7355
ADD CONSTRAINT msg_queues_pkey PRIMARY KEY (recipient_id);
7456

7557

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

8059
CREATE UNIQUE INDEX idx_msg_queues_link_id ON smp_server.msg_queues USING btree (link_id);
8160

8261

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

8763
CREATE UNIQUE INDEX idx_msg_queues_notifier_id ON smp_server.msg_queues USING btree (notifier_id);
8864

8965

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

9467
CREATE UNIQUE INDEX idx_msg_queues_sender_id ON smp_server.msg_queues USING btree (sender_id);
9568

9669

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

10171
CREATE INDEX idx_msg_queues_updated_at ON smp_server.msg_queues USING btree (deleted_at, updated_at);
10272

10373

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

tests/ServerTests/SchemaDump.hs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
module ServerTests.SchemaDump where
55

6+
import Control.Concurrent (threadDelay)
67
import Control.DeepSeq
78
import Control.Monad (unless, void)
89
import qualified Data.ByteString.Char8 as B
@@ -16,7 +17,8 @@ import Simplex.Messaging.Agent.Store.Shared (Migration (..), MigrationConfirmati
1617
import Simplex.Messaging.Server.QueueStore.Postgres.Migrations (serverMigrations)
1718
import Simplex.Messaging.Util (ifM)
1819
import System.Directory (doesFileExist, removeFile)
19-
import System.Process (readCreateProcess, shell)
20+
import System.Environment (lookupEnv)
21+
import System.Process (readCreateProcess, readCreateProcessWithExitCode, shell)
2022
import Test.Hspec
2123

2224
testDBSchema :: B.ByteString
@@ -39,8 +41,8 @@ testServerDBOpts =
3941

4042
serverSchemaDumpTest :: Spec
4143
serverSchemaDumpTest = do
42-
it "verify and overwrite schema dump" testVerifySchemaDump
43-
it "verify schema down migrations" testSchemaMigrations
44+
fit "verify and overwrite schema dump" testVerifySchemaDump
45+
fit "verify schema down migrations" testSchemaMigrations
4446

4547
testVerifySchemaDump :: IO ()
4648
testVerifySchemaDump = do
@@ -80,10 +82,17 @@ skipComparisonForDownMigrations =
8082

8183
getSchema :: FilePath -> IO String
8284
getSchema schemaPath = do
85+
ci <- (Just "true" ==) <$> lookupEnv "CI"
8386
let cmd =
8487
("pg_dump " <> B.unpack testServerDBConnstr <> " --schema " <> B.unpack testDBSchema)
85-
<> " --schema-only --no-comments --no-owner --no-privileges --no-acl --no-subscriptions --no-tablespaces --no-table-access-method > "
88+
<> " --schema-only --no-owner --no-privileges --no-acl --no-subscriptions --no-tablespaces > "
8689
<> schemaPath
87-
void $ readCreateProcess (shell cmd) ""
90+
(code, out, err) <- readCreateProcessWithExitCode (shell cmd) ""
91+
print code
92+
putStrLn $ "out: " <> out
93+
putStrLn $ "err: " <> err
94+
threadDelay 20000
95+
let sed = (if ci then "sed -i" else "sed -i ''")
96+
void $ readCreateProcess (shell $ sed <> " '/^--/d' " <> schemaPath) ""
8897
sch <- readFile schemaPath
8998
sch `deepseq` pure sch

0 commit comments

Comments
 (0)