From 194f7b8772e943dba98d672e738214808eb1a1a7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 13 Jun 2021 20:30:24 +0100 Subject: Code for setting up an initial source from scratch Includes beginnings of the end-to-end test suite. --- lib/output/pq/sql/insertSource.sql | 3 +++ lib/output/pq/updateDatabase.cpp | 16 ++++++++++++++++ lib/output/pq/updateDatabase.h | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 lib/output/pq/sql/insertSource.sql (limited to 'lib/output/pq') diff --git a/lib/output/pq/sql/insertSource.sql b/lib/output/pq/sql/insertSource.sql new file mode 100644 index 0000000..c262070 --- /dev/null +++ b/lib/output/pq/sql/insertSource.sql @@ -0,0 +1,3 @@ +INSERT INTO mygrate.source(host, username, password, port, database, filename, position, serverid, table_schema) +VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9) +RETURNING source_id diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp index 4d60fee..99d2861 100644 --- a/lib/output/pq/updateDatabase.cpp +++ b/lib/output/pq/updateDatabase.cpp @@ -1,11 +1,14 @@ #include "updateDatabase.h" #include "pqConn.h" +#include #include #include #include #include #include +#include #include +#include #include #include #include @@ -37,4 +40,17 @@ namespace MyGrate::Output::Pq { } } } + + UpdateDatabase + UpdateDatabase::createNew(PqConn * pq, const char * host, const char * username, const char * password, + unsigned short port, const char * db, int sid, const char * schema) + { + Input::MySQLConn my {host, username, password, port}; + auto ms = input::sql::showMasterStatus::execute(&my); + auto source_id = output::pq::sql::insertSource::execute( + pq, host, username, password, port, db, ms->at(0, 0), ms->at(0, 1), sid, schema); + pq->query(scprintf<"CREATE SCHEMA IF NOT EXISTS %?">(schema).c_str()); + + return UpdateDatabase(pq->connstr.c_str(), source_id->at(0, 0)); + } } diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h index 70d4fcf..8fa3b3c 100644 --- a/lib/output/pq/updateDatabase.h +++ b/lib/output/pq/updateDatabase.h @@ -32,6 +32,9 @@ namespace MyGrate::Output::Pq { EventSourceBasePtr getSource(); + static UpdateDatabase createNew(PqConn *, const char * host, const char * un, const char * pw, unsigned short p, + const char * db, int sid, const char * sc); + const uint64_t source; private: -- cgit v1.2.3