Beispiel #1
0
def drop_db():
    """Drop all of the record from tables and the tables themselves. Drop the
    database as well."""
    engine = SQLConfig().engine
    if database_exists(engine.url):
        db_session.commit()
        BaseModel.metadata.drop_all()
        drop_database(engine.url)
Beispiel #2
0
def init_db():
    """Create database if doesn't exist and create all tables."""
    engine = SQLConfig().engine
    if not database_exists(engine.url):
        LoggingManager().log("Database does not exist, creating database.",
                             LoggingLevel.INFO)
        create_database(engine.url)
    LoggingManager().log("Creating tables", LoggingLevel.INFO)
    BaseModel.metadata.create_all()
Beispiel #3
0
def drop_db():
    """Drop all of the record from tables and the tables themselves. Drop the
    database as well."""
    engine = SQLConfig().engine
    BaseModel.metadata.drop_all(bind=engine)
    drop_database(engine.url)
Beispiel #4
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from sqlalchemy import Column, Integer
from sqlalchemy.exc import DatabaseError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_utils import database_exists, create_database, drop_database

from src.catalog.sql_config import SQLConfig
from src.utils.logging_manager import LoggingLevel
from src.utils.logging_manager import LoggingManager

db_session = SQLConfig().session


class CustomModel:
    """This overrides the default `_declarative_constructor` constructor.

    It skips the attributes that are not present for the model, thus if a
    dict is passed with some unknown attributes for the model on creation,
    it won't complain for `unkwnown field`s.
    Declares and int id field for all tables
    """
    query = db_session.query_property()
    _id = Column('id', Integer, primary_key=True)

    def __init__(self, **kwargs):
        cls_ = type(self)
Beispiel #5
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from sqlalchemy import Column, Integer
from sqlalchemy.exc import DatabaseError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_utils import database_exists, create_database, drop_database

from src.catalog.sql_config import SQLConfig
from src.utils.logging_manager import LoggingLevel
from src.utils.logging_manager import LoggingManager

db_session = SQLConfig().session


class CustomModel:
    """This overrides the default `_declarative_constructor` constructor.

    It skips the attributes that are not present for the model, thus if a
    dict is passed with some unknown attributes for the model on creation,
    it won't complain for `unkwnown field`s.
    Declares and int id field for all tables
    """
    query = db_session.query_property()
    _id = Column('id', Integer, primary_key=True)

    def __init__(self, **kwargs):
        cls_ = type(self)