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

yamltodb drops database-wide objects when using a schema list #21

Closed
rhunwicks opened this issue Feb 20, 2012 · 4 comments
Closed

yamltodb drops database-wide objects when using a schema list #21

rhunwicks opened this issue Feb 20, 2012 · 4 comments
Labels

Comments

@rhunwicks
Copy link
Contributor

I have a database with some schemas in it. Some of them (postgis) create user-defined CAST functions. I also have the plpythonu language installed.

I have a yaml file that defines a new schema and I want to add the new schema without affecting the other schemas in the database so I run:

yamltodb.py -n example_schema pyrdev example.yaml

This gives me the CREATE SCHEMA, CREATE TABLE, etc. that I am expecting to create the new schema, but it also gives:

DROP CAST (postgis.box3d AS box);
DROP CAST (postgis.box3d AS postgis.box2d);
DROP CAST (postgis.geometry AS bytea);
DROP CAST (postgis.geometry AS text);
DROP CAST (postgis.geometry AS postgis.geography);
DROP CAST (postgis.geography AS postgis.geography);
DROP CAST (postgis.box2d AS postgis.box3d);
DROP CAST (postgis.geometry AS postgis.box3d);
DROP CAST (postgis.chip AS postgis.geometry);
DROP CAST (postgis.geography AS postgis.geometry);
DROP CAST (text AS postgis.geometry);
DROP CAST (postgis.box3d_extent AS postgis.box2d);
DROP CAST (postgis.box2d AS postgis.geometry);
DROP CAST (postgis.geometry AS box);
DROP CAST (postgis.box3d_extent AS postgis.box3d);
DROP CAST (bytea AS postgis.geometry);
DROP CAST (postgis.geometry AS postgis.box2d);
DROP CAST (postgis.box3d AS postgis.geometry);
DROP CAST (postgis.box3d_extent AS postgis.geometry);
DROP LANGUAGE plpythonu;

I think that when yamltodb is run with a schema list parameter it should ignore objects defined at the database-wide level.

In order for round-tripping to work as expected I would also expect dbtoyaml not to include database-wide objects when running with a schema list parameter.

@rhunwicks
Copy link
Contributor Author

Currently yamltodb attempts to drop the database-wide objects when using a schema list, even if they are defined in the yaml input file

@jmafc
Copy link
Member

jmafc commented Feb 20, 2012

I agree that yamltodb -n shouldn't be dropping database-wide objects such as casts and languages. However, I don't think dbtoyaml -n should exclude such database-wide objects, since the dbtoyaml output would then be incomplete, e.g., a function in the selected schema may be using the language in question, or a view in that schema may use a cast.

@jmafc
Copy link
Member

jmafc commented Feb 20, 2012

Could you please try the following fix:

diff --git a/pyrseas/database.py b/pyrseas/database.py
index 03d314f..3b86ee4 100644
--- a/pyrseas/database.py
+++ b/pyrseas/database.py
@@ -106,6 +106,9 @@ class Database(object):
         for sch in self.db.schemas.keys():
             if sch not in schemas:
                 del self.db.schemas[sch]
+        # exclude database-wide objects
+        self.db.languages = LanguageDict()
+        self.db.casts = CastDict()

     def from_catalog(self):
         """Populate the database objects by querying the catalogs

@jmafc
Copy link
Member

jmafc commented Mar 19, 2012

Misunderstood cause of problem in #27.

@jmafc jmafc closed this as completed Mar 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants