Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Test migration in a different schema #1336

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/com/puppetlabs/puppetdb/scf/storage_utils.clj
Expand Up @@ -69,18 +69,20 @@
(pos? (compare (sql-current-connection-database-version) version)))

(defn sql-current-connection-table-names
"Return all of the table names that are present in the database based on the
current connection. This is most useful for debugging / testing purposes
to allow introspection on the database. (Some of our unit tests rely on this.)"
"Returns the names of all of the tables in the public schema of the
current connection's database. This is most useful for debugging /
testing purposes to allow introspection on the database. (Some of
our unit tests rely on this.)."
[]
(let [query "SELECT table_name FROM information_schema.tables WHERE LOWER(table_schema) = 'public'"
results (sql/transaction (jdbc/query-to-vec query))]
(map :table_name results)))

(defn sql-current-connection-sequence-names
"Return all of the sequences that are present in the database based on the
current connection. This is most useful for debugging / testing purposes
to allow introspection on the database. (Some of our unit tests rely on this.)"
"Returns the names of all of the sequences in the public schema of
the current connection's database. This is most useful for
debugging / testing purposes to allow introspection on the
database. (Some of our unit tests rely on this.)."
[]
(let [query "SELECT sequence_name FROM information_schema.sequences WHERE LOWER(sequence_schema) = 'public'"
results (sql/transaction (jdbc/query-to-vec query))]
Expand Down
17 changes: 16 additions & 1 deletion test/com/puppetlabs/puppetdb/test/scf/migrate.clj
Expand Up @@ -3,7 +3,7 @@
[com.puppetlabs.puppetdb.scf.migrate :as migrate]
[com.puppetlabs.puppetdb.scf.migration-legacy :as legacy]
[com.puppetlabs.puppetdb.scf.storage :as store]
[com.puppetlabs.puppetdb.scf.storage-utils
[com.puppetlabs.puppetdb.scf.storage-utils :as storeutil
:refer [db-serialize postgres?]]
[cheshire.core :as json]
[clojure.java.jdbc :as sql])
Expand Down Expand Up @@ -283,3 +283,18 @@
{:value_type_id 0
:value_hash (hash/generic-identity-hash "bar")
:value_string "bar"}))))))))

(deftest migration-in-different-schema
(sql/with-connection db
(clear-db-for-testing!)
(sql/do-commands
;; Cleaned up in clear-db-for-testing!
"CREATE SCHEMA pdbtestschema"
(format "SET SCHEMA %s"
(if (postgres?) "'pdbtestschema'" "pdbtestschema")))
((migrations 1))
(record-migration! 1)
(let [tables (storeutil/sql-current-connection-table-names)]
;; Currently sql-current-connection-table-names only looks in public.
(is (empty? (storeutil/sql-current-connection-table-names)))
(migrate!))))
1 change: 1 addition & 0 deletions test/com/puppetlabs/puppetdb/testutils.clj
Expand Up @@ -78,6 +78,7 @@
that exist within it. Expects to be called from within a db binding. You
Exercise extreme caution when calling this function!"
[]
(sql/do-commands "DROP SCHEMA IF EXISTS pdbtestschema CASCADE")
(doseq [table-name (cons "test" (sutils/sql-current-connection-table-names))]
(drop-table! table-name))
(doseq [sequence-name (cons "test" (sutils/sql-current-connection-sequence-names))]
Expand Down