summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-06-13 20:30:24 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-06-13 20:30:24 +0100
commit194f7b8772e943dba98d672e738214808eb1a1a7 (patch)
treeefa8d2f4e79d14e1745fae586d72cea8df68048c /lib
parentAdd missing dep on schema file (diff)
downloadmygrate-194f7b8772e943dba98d672e738214808eb1a1a7.tar.bz2
mygrate-194f7b8772e943dba98d672e738214808eb1a1a7.tar.xz
mygrate-194f7b8772e943dba98d672e738214808eb1a1a7.zip
Code for setting up an initial source from scratch
Includes beginnings of the end-to-end test suite.
Diffstat (limited to 'lib')
-rw-r--r--lib/output/pq/sql/insertSource.sql3
-rw-r--r--lib/output/pq/updateDatabase.cpp16
-rw-r--r--lib/output/pq/updateDatabase.h3
3 files changed, 22 insertions, 0 deletions
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 <compileTimeFormatter.h>
#include <cstdint>
#include <dbRecordSet.h>
#include <eventSourceBase.h>
#include <helpers.h>
#include <input/replStream.h>
+#include <input/sql/showMasterStatus.h>
#include <memory>
+#include <output/pq/sql/insertSource.h>
#include <output/pq/sql/selectColumns.h>
#include <output/pq/sql/selectSource.h>
#include <output/pq/sql/selectTables.h>
@@ -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: