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

Added ability for comma separated list filename patterns. #25

Closed
wants to merge 1 commit into from

Conversation

whalespine
Copy link
Contributor

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"

@whalespine whalespine marked this pull request as ready for review October 7, 2022 20:07
@whalespine whalespine deleted the branch bikeshedder:master October 7, 2022 20:12
@whalespine whalespine closed this Oct 7, 2022
@whalespine whalespine deleted the master branch October 7, 2022 20:12
@bikeshedder
Copy link
Owner

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 whalespine restored the master branch October 8, 2022 00:31
@whalespine
Copy link
Contributor Author

whalespine commented Oct 8, 2022

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

@whalespine whalespine reopened this Oct 8, 2022
@whalespine
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

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.

@whalespine whalespine closed this Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants