def test98ModelDelete(self): tmodel = self.TModel.all().get() key = tmodel.get_keyvalue() tmodel.delete() sql = "select * from %s where uid = $uid" % tmodel.get_modelname() result = dbutil.get_dbconn().query(sql, vars={'uid':key}) self.assertEqual(len(result), 0)
def _downgrade(self, modifier_id): conn = dbutil.get_dbconn() b = self._exist_column("task_task", "actual_startdate") if b is True: sql = "ALTER TABLE task_task DROP actual_startdate;" conn.query(sql) b = self._exist_column("task_task", "actual_finishdate") if b is True: sql = "ALTER TABLE task_task DROP actual_finishdate;" conn.query(sql) b = self._exist_column("task_task", "t_type_code") if b is True: sql = "ALTER TABLE task_task DROP t_type_code;" conn.query(sql) b = self._exist_column("cont_group", "is_shared", conn) if b is True: sql = "ALTER TABLE cont_group CHANGE is_shared is_project TINYINT(1)" conn.query(sql) b = self._exist_column("cont_group", "group_startdate") if b is True: sql = "ALTER TABLE cont_group CHANGE group_startdate proj_startdate DATE NULL DEFAULT NULL;" conn.query(sql) b = self._exist_column("cont_group", "group_finishdate") if b is True: sql = "ALTER TABLE cont_group CHANGE group_finishdate proj_finishdate DATE NULL DEFAULT NULL;" conn.query(sql)
def _upgrade(self, modifier_id): conn = dbutil.get_dbconn() b = self._exist_column("cont_contact", "ct_company_address") if b is False: sql = "ALTER TABLE cont_contact ADD ct_company_address VARCHAR(200) NULL DEFAULT NULL AFTER ct_company;" conn.query(sql) b = self._exist_column("cont_contact", "bind_user_id") if b is False: sql = "ALTER TABLE cont_contact ADD bind_user_id INT(11) NULL DEFAULT NULL;" conn.query(sql) b = self._exist_column("cont_group", "is_project") if b is False: sql = "ALTER TABLE cont_group ADD is_project TINYINT(1) NOT NULL DEFAULT 0 AFTER uid;" conn.query(sql) b = self._exist_column("cont_group", "proj_startdate") if b is False: sql = "ALTER TABLE cont_group ADD proj_startdate DATE NULL DEFAULT NULL;" conn.query(sql) b = self._exist_column("cont_group", "proj_finishdate") if b is False: sql = "ALTER TABLE cont_group ADD proj_finishdate DATE NULL DEFAULT NULL;" conn.query(sql) b = self._exist_column("task_worksheet", "group_id") if b is False: sql = "ALTER TABLE task_worksheet ADD group_id INT(11) NULL DEFAULT NULL;" conn.query(sql) sql = "UPDATE task_worksheet SET group_id = -1;" conn.query(sql) b = self._exist_column("note_notebook", "group_id") if b is False: sql = "ALTER TABLE note_notebook ADD group_id INT(11) NULL DEFAULT NULL;" conn.query(sql) sql = "UPDATE note_notebook SET group_id = -1;" conn.query(sql) self._change_user_id_to_creator_id(conn) sql = "DELETE FROM core_i18n WHERE i1_key = 'task_confirm_movetask'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'note_confirm_movenote'" conn.query(sql)
def _downgrade(self, modifier_id): conn = dbutil.get_dbconn() b = self._exist_column("cont_contact", "ct_company_address") if b is True: sql = "ALTER TABLE cont_contact DROP ct_company_address;" conn.query(sql) b = self._exist_column("cont_contact", "bind_user_id") if b is True: sql = "ALTER TABLE cont_contact DROP bind_user_id;" conn.query(sql) b = self._exist_column("cont_group", "is_project") if b is True: sql = "ALTER TABLE cont_group DROP is_project;" conn.query(sql) b = self._exist_column("cont_group", "is_shared") if b is True: sql = "ALTER TABLE cont_group DROP is_shared;" conn.query(sql) b = self._exist_column("cont_group", "proj_startdate") if b is True: sql = "ALTER TABLE cont_group DROP proj_startdate;" conn.query(sql) b = self._exist_column("cont_group", "proj_finishdate") if b is True: sql = "ALTER TABLE cont_group DROP proj_finishdate;" conn.query(sql) b = self._exist_column("task_worksheet", "group_id") if b is True: sql = "ALTER TABLE task_worksheet DROP group_id;" conn.query(sql) b = self._exist_column("note_notebook", "group_id") if b is True: sql = "ALTER TABLE note_notebook DROP group_id;" conn.query(sql) self._change_creator_id_to_user_id(conn)
def test01CreateAndGetById(self): tmodel = self.TModel() tmodel.f_str = "abcd" tmodel.f_int = 100 tmodel.f_float = 1000.0 tmodel.f_bool = False tmodel.f_date = properti.DateProperty.utctoday() utc = datetime.datetime.utcnow() utc = utc.replace(microsecond=0) tmodel.f_datetime = utc tmodel.create() self.assertIsNotNone(tmodel.get_keyvalue()) self.assertNotEqual(tmodel.get_keyvalue(), 0) sql = "select uid from core_uid where model_name = $mn" result = dbutil.get_dbconn().query(sql, vars={'mn':tmodel.get_modelname()}) self.assertEqual(result[0].uid, tmodel.get_keyvalue()) tmodel2 = self.TModel.get_by_key(tmodel.get_keyvalue()) self.assertEqual(tmodel.f_str, tmodel2.f_str) self.assertEqual(tmodel.f_int, tmodel2.f_int) self.assertEqual(tmodel.f_float, tmodel2.f_float) self.assertEqual(tmodel.f_bool, tmodel2.f_bool) self.assertEqual(utc, tmodel2.f_datetime) self.assertEqual(properti.DateProperty.utctoday(), tmodel2.f_date)
def test03GetConn(self): db1 = dbutil.get_dbconn(self.dbinfo) self.assertIsNotNone(db1)
def _upgrade(self, modifier_id): conn = dbutil.get_dbconn() b = self._exist_column("task_task", "actual_startdate") if b is False: sql = "ALTER TABLE task_task ADD actual_startdate DATE;" conn.query(sql) b = self._exist_column("task_task", "actual_finishdate") if b is False: sql = "ALTER TABLE task_task ADD actual_finishdate DATE;" conn.query(sql) sql = "UPDATE task_task SET actual_startdate = due_startdate WHERE t_status_code != 'task_code_open';" conn.query(sql) sql = "UPDATE task_task SET actual_finishdate = modified_time WHERE t_status_code = 'task_code_closed';" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'task_label_duestarttime'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'task_label_duefinishtime'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'cont_label_isproject'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'cont_label_projectgroup'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'cont_label_projecttip'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'task_label_project'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'cont_label_projstartdate'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'cont_label_projfinishdate'" conn.query(sql) sql = "DELETE FROM core_i18n WHERE i1_key = 'task_code_meeting'" conn.query(sql) b = self._exist_column("task_task", "t_type_code") if b is False: sql = "ALTER TABLE task_task ADD t_type_code VARCHAR(20) NULL;" conn.query(sql) sql = "UPDATE task_task SET t_type_code = 'task_code_task';" conn.query(sql) b = self._exist_column("cont_group", "is_project", conn) if b is True: if not self._exist_column("cont_group", "is_shared", conn): sql = "ALTER TABLE cont_group CHANGE is_project is_shared TINYINT(1)" conn.query(sql) else: sql = "ALTER TABLE cont_group DROP is_project" conn.query(sql) b = self._exist_column("cont_group", "proj_startdate") if b is True: if not self._exist_column("cont_group", "group_startdate"): sql = "ALTER TABLE cont_group CHANGE proj_startdate group_startdate DATE NULL DEFAULT NULL;" conn.query(sql) else: sql = "ALTER TABLE cont_group DROP proj_startdate" conn.query(sql) b = self._exist_column("cont_group", "proj_finishdate") if b is True: if not self._exist_column("cont_group", "group_finishdate"): sql = "ALTER TABLE cont_group CHANGE proj_finishdate group_finishdate DATE NULL DEFAULT NULL;" conn.query(sql) else: sql = "ALTER TABLE cont_group DROP proj_finishdate" conn.query(sql)
def test99ModelDelete(self): self.TModel.delete_table() sql = "SHOW TABLES LIKE '%s'" % self.TModel.get_modelname() result = dbutil.get_dbconn().query(sql) self.assertEqual(len(result), 0)
import conf from core import migration import web web.config.debug = conf.get_web_config_debug() web.config.debug_sql = conf.get_config_debug_sql() migration.setup_db() webapp = web.application(conf.URLs, globals()) if web.config.get('_session') is None: from core.db import dbutil from core.model import Session session = web.session.Session(webapp, web.session.DBStore(dbutil.get_dbconn(), Session.get_modelname()), initializer={}) web.config._session = session web.config.session_parameters['timeout'] = conf.get_session_timeout() else: session = web.config._session def session_hook(): web.ctx.session = session webapp.add_processor(web.loadhook(session_hook)) def notfound(): return "Not Found" def main(): webapp.run()
def __get_conn(): conn = dbutil.get_dbconn() return conn