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

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

The tables are correctly generated and the migration does not show major problem. Good!

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 ea_model.ceda_moles.ceda_observation.ceda_observation import CEDA_Observation
13from sqlalchemy.orm import joinedload
14from ea_model.moles3_4.observation.mo_observation import MO_Observation
15
16SITE_ROOT = '/misc/frigid3/humid1/mnagni/workspaces/moles3/MolesManager/src'
17
18MOLES3DB_SCRIPT = '/misc/frigid3/humid1/mnagni/workspaces/moles3/MolesManager/src/sqlTables.py'
19MigrationDB_SCRIPT = SITE_ROOT + '/libs/migration/db/migrationTables.py'
20
21_MOLES3DB = DBConnection('postgresql://badc:rotyn217m@neptune.badc.rl.ac.uk:5432/Moles3')
22_MOLES3DB.initTables(DBScript(MOLES3DB_SCRIPT))
23_MOLES3DB.initTables(DBScript(MigrationDB_SCRIPT))
24MOLES3DB = _MOLES3DB
25
26
27def _buildFilter(key, keyValue):
28    return '%s = \'%s\'' % (key, keyValue)
29
30def findCEDAObservationByDeplID(id, session):
31    return getObjectId(CEDA_Observation, id, session)
32    '''
33    return session.query(CEDA_Observation).options(joinedload('relatedParty')).get(id)
34    '''
35
36def getObservationMigrationByName(deplName, session):
37    return session.query(ObservationMigration).filter(*[_buildFilter('depl_name', deplName)]).first()           
38
39def getObservationCollectionMigrationOrderByDate(session):
40    data_ents = getAllObjects(ObservationCollectionMigration, session)
41    return data_ents.order_by(asc("data_ent_creation"))   
42       
43   
Note: See TracBrowser for help on using the repository browser.