-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from lsst/tickets/DM-46130
DM-46130: Add tools for comparing two schemas or a schema and a database
- Loading branch information
Showing
17 changed files
with
878 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add tools for comparing schemas in the `diff` module. | ||
These can be run from the command line using `felis diff`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Database utilities for Felis schemas.""" | ||
|
||
# This file is part of felis. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from sqlalchemy import Engine, create_engine | ||
|
||
from ..datamodel import Schema | ||
from ..metadata import MetaDataBuilder | ||
from .utils import DatabaseContext | ||
|
||
__all__ = ["create_database"] | ||
|
||
|
||
def create_database(schema: Schema, engine_or_url_str: Engine | str | None = None) -> DatabaseContext: | ||
""" | ||
Create a database from the specified `Schema`. | ||
Parameters | ||
---------- | ||
schema | ||
The schema to create. | ||
engine_or_url_str | ||
The SQLAlchemy engine or URL to use for database creation. | ||
If None, an in-memory SQLite database will be created. | ||
Returns | ||
------- | ||
`DatabaseContext` | ||
The database context object. | ||
""" | ||
if engine_or_url_str is not None: | ||
engine = ( | ||
engine_or_url_str if isinstance(engine_or_url_str, Engine) else create_engine(engine_or_url_str) | ||
) | ||
else: | ||
engine = create_engine("sqlite:///:memory:") | ||
apply_schema = False if engine.url.drivername == "sqlite" else True | ||
metadata = MetaDataBuilder( | ||
schema, apply_schema_to_metadata=apply_schema, apply_schema_to_tables=apply_schema | ||
).build() | ||
ctx = DatabaseContext(metadata, engine) | ||
ctx.initialize() | ||
ctx.create_all() | ||
return ctx |
Oops, something went wrong.