bikeshedder / tusker

PostgreSQL migration management tool
The Unlicense
208 stars 17 forks source link

Added ability for comma separated list filename patterns. #25

Closed whalespine closed 1 year ago

whalespine commented 1 year ago

This PR adds the ability to specify a comma separate list of glob patterns for the schema.filename configuration. Single pattern still works fine.

Example:

[schema]
filename = "schema/*.sql,procs/**/*.sql"
bikeshedder commented 1 year ago

I like the idea of having multiple patterns. I would prefer if it was using a List[str] though as it would look more natural in the toml file.

Is there a reason why you deleted this PR?

whalespine commented 1 year ago

Weird. I didn't delete the PR. Or maybe I hit the wrong button.

whalespine commented 1 year ago

Not sure how to add a commit to this PR. Any hints on that?

In the meantime, is this what you had in mind? Only problem I have with this is it is not backwards compatible.

index 0251f37..9e08538 100644
--- a/tusker/__init__.py
+++ b/tusker/__init__.py
@@ -109,7 +109,7 @@ class Tusker:
         with self.createdb('schema') as schema_engine:
             with schema_engine.begin() as schema_cursor:
                 self.log('Creating original schema...')
-                for pattern in self.config.schema.filename.split(","):
+                for pattern in self.config.schema.filename:
                     for filename in sorted(glob(pattern, recursive=True)):
                         self.log('- {}'.format(filename))
                         execute_sql_file(schema_cursor, filename)
diff --git a/tusker/config.py b/tusker/config.py
index 2dc1c4d..ff929a8 100644
--- a/tusker/config.py
+++ b/tusker/config.py
@@ -16,7 +16,7 @@ class Config:
             data = {}
         # time to validate some configuration variables
         data.setdefault('database', {'dbname': 'tusker'})
-        data.setdefault('schema', {'filename': 'schema.sql'})
+        data.setdefault('schema', {'filename': ['schema.sql']})
         data.setdefault('migrations', {'directory': 'migrations'})
         data.setdefault('migra', {'safe': False, 'privileges': False})
         self.schema = SchemaConfig(data['schema'])
@@ -55,7 +55,7 @@ class SchemaConfig:

     def __init__(self, data):
         data = ConfigReader(data, 'schema')
-        self.filename = data.get('filename', str) or 'schema.sql'
+        self.filename = data.get('filename', list) or ['schema.sql']

     def __str__(self):
         return 'SchemaConfig({!r})'.format(self.__dict__)
bikeshedder commented 1 year ago

You can just add commits to your branch. It will automatically added to the PR.

A PR is in essence just a "please merge my branch" request. So if you change the branch the PR changes as well.

Regarding the Implementation you could just add a if isinstance(filename, str): and support both formats that way.

whalespine commented 1 year ago

Doesn't seem to have worked. I've done this from branch to branch but never from a fork. Could that be an issue? I may close this PR and create another one.