Ejemplo n.º 1
0
    # USING btree
    # ("when");""")

    session().connection().execute(
        "GRANT ALL ON horse.audit_trail  TO horse_clt ;")
    session().connection().execute(
        "GRANT ALL ON SEQUENCE horse.audit_trail_id_generator  TO horse_clt ;")

    # session().connection().execute("ALTER TABLE horse.delivery_slip ADD COLUMN active boolean DEFAULT true;")
    # session().connection().execute("ALTER TABLE horse.delivery_slip ALTER COLUMN active SET NOT NULL;")

    session().commit()


def alter_data():

    #     session().connection().execute("""
    # update horse.delivery_slip_parts
    # set sell_price = horse.delivery_slip_parts.quantity_out * horse.order_parts.sell_price
    # from horse.order_parts
    # where horse.order_parts.order_part_id = horse.delivery_slip_parts.order_part_id
    # """
    session().commit()


args = parser.parse_args()
init_db_session(args.db_url, metadata, False or configuration.echo_query)
from dao import dao
alter_structure()
alter_data()
Ejemplo n.º 2
0
from sqlalchemy.sql import select,func,and_,or_

from Logging import mainlog,init_logging
from Configurator import init_i18n,load_configuration,configuration,resource_dir
init_logging()
init_i18n()
load_configuration()

from db_mapping import metadata
from datalayer.database_session import init_db_session

from datalayer.database_session import session
from db_mapping import FilterQuery


init_db_session(configuration.database_url, metadata, False or configuration.echo_query)

from dao import dao

def alter_structure():

    session().connection().execute("""CREATE TABLE horse.filter_queries (
        filter_query_id SERIAL NOT NULL,
        name VARCHAR NOT NULL,
        query VARCHAR NOT NULL,
        shared BOOLEAN NOT NULL,
        owner_id INTEGER NOT NULL,
        PRIMARY KEY (filter_query_id),
        CONSTRAINT fq_by_name UNIQUE (name, owner_id),
        FOREIGN KEY(owner_id) REFERENCES horse.employees (employee_id))""")
Ejemplo n.º 3
0
from sqlalchemy.sql import select, func, and_, or_

from Logging import mainlog, init_logging
from Configurator import init_i18n, load_configuration, configuration, resource_dir

init_logging()
init_i18n()
load_configuration()

from db_mapping import metadata
from datalayer.database_session import init_db_session

from datalayer.database_session import session
from db_mapping import OrderStatusType, OrderPartStateType, OrderPart, Order, DeliverySlip, DeliverySlipPart

init_db_session(configuration.database_url.replace('horse_clt', 'horse_clt'),
                metadata, False or configuration.echo_query)

from dao import dao


def alter_structure():
    pass


def alter_data():

    q = session().query(OrderPart).filter(
        and_(OrderPart.state == OrderPartStateType.completed,
             OrderPart.completed_date == None)).all()

    mainlog.info("Updating {} completed records".format(len(q)))