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

Add upgrade DB to CLI #319

Merged
merged 9 commits into from Jul 18, 2019
Merged

Add upgrade DB to CLI #319

merged 9 commits into from Jul 18, 2019

Conversation

doaa-altarawy
Copy link
Contributor

@doaa-altarawy doaa-altarawy commented Jul 12, 2019

Description

Added alembic migrations to the CLI using the command qcfractal-server upgrade.

TODO:

[x] Add testing

Status

  • Changelog updated
  • Ready to go

@doaa-altarawy doaa-altarawy added Database Related to the database storage layer Feature Adds a new feature to the project labels Jul 12, 2019
@doaa-altarawy doaa-altarawy self-assigned this Jul 12, 2019
@doaa-altarawy doaa-altarawy added this to the v0.8.0 milestone Jul 12, 2019
Copy link
Contributor

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I look forward to this.

Can we go ahead and connect a SQL Engine to the database to mint the schemas and go ahead and run stamp on the init as well? I think this should work around the problem.

qcfractal/alembic/env.py Outdated Show resolved Hide resolved
@@ -226,7 +239,7 @@ def server_start(args, config):
logfile = str(config.base_path / config.fractal.logfile)

print("\n>>> Checking the PostgreSQL connection...")
database_name = args.get("database_name", None) or config.database.default_database
database_name = config.database.database_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create this alias, is it possible just to use it directly below?

@@ -100,6 +102,9 @@ class Config(SettingsCommonConfig):

class FractalConfig(ConfigSettings):

# class variable, not in the pydantic model
defaults_file_path: ClassVar[str] = os.path.expanduser("~/.qca/qcfractal_defaults.yaml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other thing to do here is use a _defaults_file_path. This will tell pydantic to automatically consider it a class var.

if Path(FractalConfig.defaults_file_path).exists():
with open(FractalConfig.defaults_file_path, "r") as handle:
kwargs['base_folder'] = yaml.load(handle.read(),
Loader=yaml.FullLoader)['default_base_folder']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Not bad.


if ret['retcode'] != 0:
raise ValueError("\nFailed to Upgrade the database, make sure to init the database first before being able to upgrade it.\n")
print(ret)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This print statement will not be executed.


cmd = [shutil.which('alembic'),
'-c', self._alembic_ini,
'-x', 'uri='+self.config.database_uri(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a f-string here to match other areas?


ret = self._run([shutil.which('alembic'),
'-c', self._alembic_ini,
'-x', 'uri='+self.config.database_uri(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on f-string.

@@ -315,7 +315,6 @@ def start(self, timeout: int = 5) -> None:
self._qcfractal_proc = _background_process([
shutil.which("qcfractal-server"),
"start",
f"--database-name={self._dbname}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will create some restart issues. I think we will need to init a new temporary folder and qcfractal-init into that every time.

@lgtm-com
Copy link

lgtm-com bot commented Jul 17, 2019

This pull request introduces 5 alerts when merging 01111a8 into e96ff16 - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 2 for Unreachable code
  • 1 for Missing call to __init__ during object initialization

@codecov-io
Copy link

Codecov Report

Merging #319 into master will decrease coverage by 2.2%.
The diff coverage is 75.58%.

@lgtm-com
Copy link

lgtm-com bot commented Jul 18, 2019

This pull request introduces 3 alerts when merging 2549ae3 into ea58476 - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Missing call to __init__ during object initialization

Copy link
Contributor

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Ready to merge?

@doaa-altarawy
Copy link
Contributor Author

Yes, ready to merge.

@dgasmith dgasmith merged commit a461194 into MolSSI:master Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Database Related to the database storage layer Feature Adds a new feature to the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants