Example #1
0
def migrate(cr, version):
    if table_exists(cr, "queue_job") and not column_exists(
        cr, "queue_job", "exec_time"
    ):
        # Disable trigger otherwise the update takes ages.
        cr.execute(
            """
            ALTER TABLE queue_job DISABLE TRIGGER queue_job_notify;
        """
        )
        cr.execute(
            """
            ALTER TABLE queue_job ADD COLUMN exec_time double precision DEFAULT 0;
        """
        )
        cr.execute(
            """
            UPDATE
                queue_job
            SET
                exec_time = EXTRACT(EPOCH FROM (date_done - date_started));
        """
        )
        cr.execute(
            """
            ALTER TABLE queue_job ENABLE TRIGGER queue_job_notify;
        """
        )
 def _create_model_and_fields(self):
     for sql_view in self:
         # Create model
         sql_view.model_id = self.env["ir.model"].create(self._prepare_model()).id
         sql_view.rule_id = self.env["ir.rule"].create(self._prepare_rule()).id
         # Drop table, created by the ORM
         if sql.table_exists(self._cr, sql_view.view_name):
             req = "DROP TABLE %s" % sql_view.view_name
             self._log_execute(req)
Example #3
0
def migrate(cr, version):
    if not table_exists(cr, "queue_job"):
        return
    if not column_exists(cr, "queue_job", "records"):
        cr.execute("""
            ALTER TABLE queue_job
            ADD COLUMN records text;
        """)
    cr.execute("""
    UPDATE queue_job
    SET records = '{"_type": "odoo_recordset"'
    || ', "model": "' || model_name || '"'
    || ', "uid": ' || user_id
    || ', "ids": ' || record_ids
    || '}'
    WHERE records IS NULL;
    """)
Example #4
0
    def _view_needs_update(self, cursor):
        """ Middle SQL VIEW should be update if required
        argument values has been given and:
            1. VIEW not exists in database
            2. Relation is a TABLE instead a VIEW
            3. VIEW column names not match with field column names
        """
        result = False

        if not sqltools.table_exists(cursor, self.relation):
            result = True
        elif self._relation_is_actually_a_table(cursor):
            result = True
        elif not self._column_names_match(cursor):
            result = True

        return result