-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into permissions_remodel_new
- Loading branch information
Showing
18 changed files
with
343 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,53 @@ | ||
from db.schemas.operations.alter import comment_on_schema | ||
from db.connection import execute_msar_func_with_engine | ||
from db.connection import execute_msar_func_with_engine, exec_msar_func | ||
|
||
|
||
def create_schema(schema_name, engine, comment=None, if_not_exists=False): | ||
def create_schema_via_sql_alchemy(schema_name, engine, description=None): | ||
""" | ||
Creates a schema. | ||
Creates a schema using a SQLAlchemy engine. | ||
Args: | ||
schema_name: Name of the schema to create. | ||
engine: SQLAlchemy engine object for connecting. | ||
comment: The new comment. Any quotes or special characters must | ||
be escaped. | ||
if_not_exists: Whether to ignore an error if the schema does | ||
exist. | ||
description: A new description to set on the schema. | ||
If a schema already exists with the given name, this function will raise an error. | ||
Returns: | ||
Returns a string giving the command that was run. | ||
The integer oid of the newly created schema. | ||
""" | ||
result = execute_msar_func_with_engine( | ||
engine, 'create_schema', schema_name, if_not_exists | ||
return execute_msar_func_with_engine( | ||
engine, 'create_schema', schema_name, description | ||
).fetchone()[0] | ||
|
||
if comment: | ||
comment_on_schema(schema_name, engine, comment) | ||
return result | ||
|
||
def create_schema_if_not_exists_via_sql_alchemy(schema_name, engine): | ||
""" | ||
Ensure that a schema exists using a SQLAlchemy engine. | ||
Args: | ||
schema_name: Name of the schema to create. | ||
engine: SQLAlchemy engine object for connecting. | ||
Returns: | ||
The integer oid of the newly created schema. | ||
""" | ||
return execute_msar_func_with_engine( | ||
engine, 'create_schema_if_not_exists', schema_name | ||
).fetchone()[0] | ||
|
||
|
||
def create_schema(schema_name, conn, description=None): | ||
""" | ||
Create a schema using a psycopg connection. | ||
Args: | ||
schema_name: Name of the schema to create. | ||
conn: a psycopg connection | ||
description: A new description to set on the schema. | ||
If a schema already exists with the given name, this function will raise an error. | ||
Returns: | ||
The integer oid of the newly created schema. | ||
""" | ||
return exec_msar_func(conn, 'create_schema', schema_name, description).fetchone()[0] |
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
Oops, something went wrong.