def migrateCompanyTable(context): from z3c.saconfig import Session from euphorie.deployment.upgrade.utils import ColumnExists from euphorie.deployment.upgrade.utils import TableExists from euphorie.client import model from zope.sqlalchemy import datamanager import transaction session = Session() if ColumnExists(session, "company", "referer"): return if TableExists(session, "company"): log.info("Moving company table to dutch_company") session.execute("ALTER TABLE company RENAME TO dutch_company") session.execute( "ALTER SEQUENCE company_id_seq RENAME TO dutch_company_id_seq") session.execute( "ALTER INDEX ix_company_session_id RENAME TO " "ix_dutch_company_session_id") model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Creating new company table")
def drop_constraint_no_duplicates_in_tree(context): session = Session() if TableExists(session, "tree"): session.execute("ALTER TABLE tree DROP CONSTRAINT no_duplicates") model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Removed the constraint `no_duplicates` from table tree.")
def increase_sessions_path_column(context): session = Session() if TableExists(session, "session"): session.execute("ALTER TABLE session ALTER COLUMN zodb_path TYPE varchar(512)") model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Increased the size of column zodb_path in table session.")
def enable_custom_risks_on_all_modules(context): """ """ if not api.portal.get_registry_record("euphorie.allow_user_defined_risks"): log.warning( "Custom risks are not enabled. Set 'allow_user_defined_risks' to " "true in euphorie.ini for enabling them." ) return portal = api.portal.get() client = portal.client count = 0 for country in client.objectValues(): if IClientCountry.providedBy(country): for sector in country.objectValues(): if IClientSector.providedBy(sector): for survey in sector.objectValues(): try: is_new = EnableCustomRisks(survey) count += 1 custom = getattr(survey, "custom-risks", None) if custom: custom.title = _( "title_other_risks", default="Added risks (by you)", ) custom.description = _( "description_other_risks", default="In case you have identified risks not included in " # noqa: E501 "the tool, you are able to add them now:", ) custom.question = _( "question_other_risks", default="<p>Would you now like to add your own defined risks " # noqa: E501 "to this tool?</p><p><strong>Important:</strong> In " # noqa: E501 "order to avoid duplicating risks, we strongly recommend you " # noqa: E501 "to go first through all the previous modules, if you have not " # noqa: E501 "done it yet.</p><p>If you don't need to add risks, please select 'No.'</p>", # noqa: E501 ) if is_new: survey.published = ( survey.id, survey.title, datetime.datetime.now(), ) except Exception as e: log.error( "Could not enable custom risks for module. %s" % e ) log.info("All %d published surveys can now have custom risks." % count) session = Session() if TableExists(session, "tree"): session.execute( "UPDATE tree SET title = 'title_other_risks' WHERE zodb_path ='custom-risks'" # noqa: E501 ) model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Set correct title on all exisiting sessions for custom risks module.")
def alter_time_column(context): session = Session() if TableExists(session, "statistics_login"): session.execute( "ALTER TABLE statistics_login ALTER COLUMN time SET DEFAULT CURRENT_TIMESTAMP" ) model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Changed default for column 'time' to current timestamp")
def add_wp_column_to_company(context): session = Session() if TableExists(session, "company"): session.execute( "ALTER TABLE company ADD workers_participated bool DEFAULT NULL") model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Added new column 'workers_participated' to table 'company'")
def TableExists(self, session, table): from euphorie.deployment.upgrade.utils import TableExists return TableExists(session, table)
def add_od_table(context): session = Session() if not TableExists(session, OdLink.__tablename__): OdLink.__table__.create(session.bind) log.info("Added new 'od_link' table")
u"<p>Would you now like to add your own defined risks " u"to this tool?</p><p><strong>Important:</strong> In " u"order to avoid duplicating risks, we strongly recommend you " u"to go first through all the previous modules, if you have not " u"done it yet.</p><p>If you don't need to add risks, please select 'No.'</p>" ) if is_new: survey.published = (survey.id, survey.title, datetime.datetime.now()) except Exception, e: log.error( "Could not enable custom risks for module. %s" % e) log.info('All %d published surveys can now have custom risks.' % count) session = Session() if TableExists(session, "tree"): session.execute( "UPDATE tree SET title = 'title_other_risks' WHERE zodb_path ='custom-risks'" ) model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info( 'Set correct title on all exisiting sessions for custom risks module.' ) def install_private_resources(context): """ Install the oira.private egg, which contains non-free JS and CSS resources. """