source: mauRepo/MolesManager/trunk/src/libs/migration/db/dbConnection.py @ 8042

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/db/dbConnection.py@8042
Revision 8042, 1.5 KB checked in by mnagni, 8 years ago (diff)

The tables are correctly generated but still some problem with class initialization.
Migration is partially working.
Starting the deployment structure implementation.

Line 
1'''
2Created on 14 Nov 2011
3
4@author: mnagni
5'''
6
7from db_manager.dbConnection import DBConnection, DBScript
8from libs.migration.db.classes import ObservationMigration,\
9    ObservationCollectionMigration
10from libs.commons_db import getObjectId, getAllObjects
11from sqlalchemy.sql.expression import asc
12from sqlalchemy.orm import joinedload
13from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation
14
15SITE_ROOT = '/misc/frigid3/humid1/mnagni/workspaces/moles3/MolesManager/src'
16
17MOLES3DB_SCRIPT = '/misc/frigid3/humid1/mnagni/workspaces/moles3/MolesManager/src/sqlTables.py'
18MigrationDB_SCRIPT = SITE_ROOT + '/libs/migration/db/migrationTables.py'
19
20_MOLES3DB = DBConnection('postgresql://badc:rotyn217m@neptune.badc.rl.ac.uk:5432/Moles3')
21_MOLES3DB.initTables(DBScript(MOLES3DB_SCRIPT))
22_MOLES3DB.initTables(DBScript(MigrationDB_SCRIPT))
23MOLES3DB = _MOLES3DB
24
25
26def _buildFilter(key, keyValue):
27    return '%s = \'%s\'' % (key, keyValue)
28
29def findCEDAObservationByDeplID(id, session):
30    return getObjectId(CEDA_Observation, id, session)
31    '''
32    return session.query(CEDA_Observation).options(joinedload('relatedParty')).get(id)
33    '''
34
35def getObservationMigrationByName(deplName, session):
36    return session.query(ObservationMigration).filter(*[_buildFilter('depl_name', deplName)]).first()           
37
38def getObservationCollectionMigrationOrderByDate(session):
39    data_ents = getAllObjects(ObservationCollectionMigration, session)
40    return data_ents.order_by(asc("data_ent_creation"))   
41       
42   
Note: See TracBrowser for help on using the repository browser.