diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-01 00:17:38 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-01 00:17:38 +0100 |
commit | 046cdae1a14a686238ab91b1f883335b2de5a78c (patch) | |
tree | 3fcf031cc9db3d40d65f6ec989b22d97a2dab11e /lib/output/pq/sql | |
parent | Read test DB connection details from env (diff) | |
download | mygrate-046cdae1a14a686238ab91b1f883335b2de5a78c.tar.bz2 mygrate-046cdae1a14a686238ab91b1f883335b2de5a78c.tar.xz mygrate-046cdae1a14a686238ab91b1f883335b2de5a78c.zip |
Generate DbStmt templates from .sql files
m4 generator and related code. Reshuffles some CTF stuff to avoid
pulling in all of CTF and iostream for its fixed_string. Moves CTF out
of AdHoc namespace.
Add some initial SQL statements.
Diffstat (limited to 'lib/output/pq/sql')
-rw-r--r-- | lib/output/pq/sql/selectColumns.sql | 6 | ||||
-rw-r--r-- | lib/output/pq/sql/selectSource.sql | 3 | ||||
-rw-r--r-- | lib/output/pq/sql/selectTables.sql | 6 | ||||
-rw-r--r-- | lib/output/pq/sql/updateSourcePosition.sql | 4 |
4 files changed, 19 insertions, 0 deletions
diff --git a/lib/output/pq/sql/selectColumns.sql b/lib/output/pq/sql/selectColumns.sql new file mode 100644 index 0000000..e9cd107 --- /dev/null +++ b/lib/output/pq/sql/selectColumns.sql @@ -0,0 +1,6 @@ +SELECT t.table_name, STRING_AGG(c.column_name, '|' ORDER BY c.ordinal_position) +FROM mygrate.source s + JOIN information_schema.tables t USING(table_schema) + LEFT OUTER JOIN information_schema.columns c USING(table_schema, table_name) +WHERE s.id = $1 +GROUP BY t.table_name diff --git a/lib/output/pq/sql/selectSource.sql b/lib/output/pq/sql/selectSource.sql new file mode 100644 index 0000000..3048410 --- /dev/null +++ b/lib/output/pq/sql/selectSource.sql @@ -0,0 +1,3 @@ +SELECT host, username, password, port, filename, position, serverid, table_schema +FROM mygrate.source s +WHERE s.id = $1 diff --git a/lib/output/pq/sql/selectTables.sql b/lib/output/pq/sql/selectTables.sql new file mode 100644 index 0000000..389dfe2 --- /dev/null +++ b/lib/output/pq/sql/selectTables.sql @@ -0,0 +1,6 @@ +SELECT t.table_name, STRING_AGG(k.column_name, '|' ORDER BY k.ordinal_position) pk_cols +FROM mygrate.source s + JOIN information_schema.tables t USING(table_schema) + LEFT OUTER JOIN information_schema.key_column_usage k USING(table_schema, table_name) +WHERE s.id = $1 +GROUP BY t.table_name diff --git a/lib/output/pq/sql/updateSourcePosition.sql b/lib/output/pq/sql/updateSourcePosition.sql new file mode 100644 index 0000000..3d3d665 --- /dev/null +++ b/lib/output/pq/sql/updateSourcePosition.sql @@ -0,0 +1,4 @@ +UPDATE mygrate.source SET + filename = $1, + position = $2 +WHERE id = $3 |