def __register__(cls, module_name): TimesheetWork = Pool().get('timesheet.work') cursor = Transaction().cursor table_project_work = TableHandler(cursor, cls, module_name) table_timesheet_work = TableHandler(cursor, TimesheetWork, module_name) migrate_sequence = (not table_project_work.column_exist('sequence') and table_timesheet_work.column_exist('sequence')) super(Work, cls).__register__(module_name) # Migration from 2.0: copy sequence from timesheet to project if migrate_sequence: cursor.execute( 'SELECT t.sequence, t.id ' 'FROM "%s" AS t ' 'JOIN "%s" AS p ON (p.work = t.id)' % ( TimesheetWork._table, cls._table)) for sequence, id_ in cursor.fetchall(): sql = ('UPDATE "%s" ' 'SET sequence = %%s ' 'WHERE work = %%s' % cls._table) cursor.execute(sql, (sequence, id_)) # Migration from 2.4: drop required on sequence table_project_work.not_null_action('sequence', action='remove')
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.2: packing renamed into shipment table = TableHandler(cursor, cls, module_name) table.drop_constraint('check_packing') for suffix in ('in', 'out', 'in_return', 'out_return', 'internal'): old_column = 'packing_%s' % suffix new_column = 'shipment_%s' % suffix if table.column_exist(old_column): table.index_action(old_column, action='remove') table.drop_fk(old_column) table.column_rename(old_column, new_column) # Migration from 1.8: new field internal_quantity internal_quantity_exist = table.column_exist('internal_quantity') super(Move, cls).__register__(module_name) # Migration from 1.8: fill new field internal_quantity if not internal_quantity_exist: offset = 0 limit = cursor.IN_MAX moves = True while moves: moves = cls.search([], offset=offset, limit=limit) offset += limit for move in moves: internal_quantity = cls._get_internal_quantity( move.quantity, move.uom, move.product) cursor.execute( 'UPDATE "' + cls._table + '" ' 'SET internal_quantity = %s ' 'WHERE id = %s', (internal_quantity, move.id)) table = TableHandler(cursor, cls, module_name) table.not_null_action('internal_quantity', action='add') # Migration from 1.0 check_packing_in_out has been removed table = TableHandler(cursor, cls, module_name) table.drop_constraint('check_packing_in_out') # Migration from 2.6: merge all shipments table.drop_constraint('check_shipment') shipments = { 'shipment_in': 'stock.shipment.in', 'shipment_out': 'stock.shipment.out', 'shipment_out_return': 'stock.shipment.out.return', 'shipment_in_return': 'stock.shipment.in.return', 'shipment_internal': 'stock.shipment.internal', } for column, model in shipments.iteritems(): if table.column_exist(column): cursor.execute('UPDATE "' + cls._table + '" ' 'SET shipment = \'' + model + ',\' || "' + column + '" ' 'WHERE "' + column + '" IS NOT NULL') table.drop_column(column) # Add index on create_date table.index_action('create_date', action='add')
def __register__(cls, module_name): super(GnuHealthPatient, cls).__register__(module_name) cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Move occupation from patient to party if table.column_exist('occupation'): cursor.execute ('UPDATE PARTY_PARTY ' 'SET OCCUPATION = GNUHEALTH_PATIENT.OCCUPATION ' 'FROM GNUHEALTH_PATIENT ' 'WHERE GNUHEALTH_PATIENT.NAME = PARTY_PARTY.ID') table.drop_column('occupation') # Move education from patient to party if table.column_exist('education'): cursor.execute ('UPDATE PARTY_PARTY ' 'SET EDUCATION = GNUHEALTH_PATIENT.EDUCATION ' 'FROM GNUHEALTH_PATIENT ' 'WHERE GNUHEALTH_PATIENT.NAME = PARTY_PARTY.ID') table.drop_column('education') # The following indicators are now part of the Domiciliary Unit if table.column_exist('sewers'): table.drop_column ('sewers') if table.column_exist('water'): table.drop_column ('water') if table.column_exist('trash'): table.drop_column ('trash') if table.column_exist('electricity'): table.drop_column ('electricity') if table.column_exist('gas'): table.drop_column ('gas') if table.column_exist('telephone'): table.drop_column ('telephone') if table.column_exist('internet'): table.drop_column ('internet') if table.column_exist('housing'): table.drop_column ('housing')
def __register__(cls, module_name): """Migrations :param module_name: Module Name (Automatically passed by caller) """ cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Drop the required index on methods table.not_null_action('methods', action="remove") # Rename methods to old_methods table.column_rename('methods', 'old_methods') # Check if the new boolean fields exist http_method_fields_exists = table.column_exist('http_method_get') super(URLRule, cls).__register__(module_name) if not http_method_fields_exists: # if the http method fields did not exist before this method # should transition old_methods to the boolean fields rules = cls.search([]) for rule in rules: cls.set_methods([rule.id], 'methods', rule.old_methods)
def init(self, module_name): super(ProjectWork, self).init(module_name) cursor = Transaction().cursor table = TableHandler(cursor, self, module_name) log.debug(table) if table.column_exist('billable'): log.debug("drop billable from table") table.drop_column('billable', exception=True)
def __register__(cls, module_name): super(Surgery, cls).__register__(module_name) cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Rename the date column to surgery_surgery_date if table.column_exist('date'): table.column_rename('date', 'surgery_date')
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.6 product renamed into category table = TableHandler(cursor, cls) if table.column_exist('product'): table.index_action('product', action='remove') table.drop_fk('product') table.column_rename('product', 'category') super(CategorySupplierTax, cls).__register__(module_name)
def __register__(cls, module_name): super(PaymentTermLine, cls).__register__(module_name) cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Migration from 1.0 percent change into percentage if table.column_exist("percent"): cursor.execute('UPDATE "' + cls._table + '" ' "SET percentage = percent * 100") table.drop_column("percent", exception=True) # Migration from 2.2 if table.column_exist("delay"): cursor.execute('UPDATE "' + cls._table + '" SET day = 31 ' "WHERE delay = 'end_month'") table.drop_column("delay", exception=True) lines = cls.search([]) for line in lines: if line.percentage: cls.write([line], {"divisor": cls.round(Decimal("100.0") / line.percentage, cls.divisor.digits[1])}) # Migration from 2.4: drop required on sequence table.not_null_action("sequence", action="remove")
def __register__(cls, module_name): Location = Pool().get("stock.location") cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) migrate_warehouse = not table.column_exist("warehouse") and table.column_exist("location") super(Forecast, cls).__register__(module_name) # Add index on create_date table = TableHandler(cursor, cls, module_name) table.index_action("create_date", action="add") if migrate_warehouse: location2warehouse = {} def find_warehouse(location): if location.type == "warehouse": return location.id elif location.parent: return find_warehouse(location.parent) cursor.execute('SELECT id, location FROM "%s"' % cls._table) for forecast_id, location_id in cursor.fetchall(): warehouse_id = location_id # default fallback if location_id in location2warehouse: warehouse_id = location2warehouse[location_id] else: location = Location(location_id) warehouse_id = find_warehouse(location) or location_id location2warehouse[location_id] = warehouse_id cursor.execute( 'UPDATE "%s" SET warehouse = %%s ' "WHERE id = %%s" % cls._table, (warehouse_id, forecast_id) ) table.not_null_action("warehouse", action=cls.warehouse.required and "add" or "remove") table.drop_column("location", True) # Migration from 2.0 delete stock moves forecasts = cls.search([]) cls.delete_moves(forecasts)
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.4: calendar_rdate renamed to calendar_date table = TableHandler(cursor, cls, module_name) old_column = 'calendar_rdate' if table.column_exist(old_column): table.column_rename(old_column, 'calendar_date') super(TodoRDate, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.date if table.column_exist('calendar_date'): cursor.execute('UPDATE "' + cls._table + '" AS e ' 'SET date = (SELECT a.date ' 'FROM calendar_date AS a ' 'WHERE a.id = e.calendar_date), ' 'datetime = (SELECT a.datetime ' 'FROM calendar_date AS a ' 'WHERE a.id = e.calendar_date)') table.drop_column('calendar_date', True)
def __register__(cls, module_name): cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) if not table.column_exist('uuid'): table.add_raw_column('uuid', FIELDS[cls.uuid._type].sql_type(cls.uuid), FIELDS[cls.uuid._type].sql_format, None, None) cursor.execute('SELECT id FROM "' + cls._table + '"') for id, in cursor.fetchall(): cursor.execute('UPDATE "' + cls._table + '" ' 'SET "uuid" = %s WHERE id = %s', (cls.default_uuid(), id)) super(Party, cls).__register__(module_name)
def __register__(cls, module_name): cursor = Transaction().cursor super(TodoAlarm, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.alarm if table.column_exist('calendar_alarm'): cursor.execute('UPDATE "' + cls._table + '" AS t ' 'SET valarm = (SELECT a.valarm ' 'FROM calendar_alarm AS a ' 'WHERE a.id = t.calendar_alarm)') table.drop_column('calendar_alarm', True)
def __register__(cls, module_name): cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Migration from 2.4 arch moved into data if table.column_exist("arch"): table.column_rename("arch", "data") super(View, cls).__register__(module_name) # Migration from 1.0 arch no more required table.not_null_action("arch", action="remove") # Migration from 2.4 model no more required table.not_null_action("model", action="remove")
def __register__(cls, module_name): cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Migration from 2.4 arch moved into data if table.column_exist('arch'): table.column_rename('arch', 'data') super(View, cls).__register__(module_name) # Migration from 1.0 arch no more required table.not_null_action('arch', action='remove') # Migration from 2.4 model no more required table.not_null_action('model', action='remove')
def __register__(cls, module_name): super(Journal, cls).__register__(module_name) cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Migration from 1.0 sequence Many2One change into Property if table.column_exist('sequence'): Property = Pool().get('ir.property') cursor.execute('SELECT id, sequence FROM "' + cls._table + '"') with Transaction().set_user(0): for journal_id, sequence_id in cursor.fetchall(): Property.set('sequence', cls._name, journal_id, (sequence_id and 'ir.sequence,' + str(sequence_id) or False)) table.drop_column('sequence', exception=True)
def __register__(cls, module_name): cursor = Transaction().cursor super(TodoAttendee, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.attendee if table.column_exist('calendar_attendee'): cursor.execute('UPDATE "' + cls._table + '" AS e ' 'SET email = (SELECT a.email ' 'FROM calendar_attendee AS a ' 'WHERE a.id = e.calendar_attendee), ' 'status = (SELECT a.status ' 'FROM calendar_attendee AS a ' 'WHERE a.id = e.calendar_attendee)') table.drop_column('calendar_attendee', True)
def __register__(cls, module_name): cursor = Transaction().cursor super(TodoRRule, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.rrule if table.column_exist('calendar_rrule'): for field in (f for f in dir(RRuleMixin) if isinstance(f, fields.Field)): cursor.execute(('UPDATE "' + cls._table + '" AS e ' 'SET "%(field)s" = (SELECT a."%(field)s" ' 'FROM calendar_rrule AS r ' 'WHERE r.id = e.calendar_rrule)') % {'field': field}) table.drop_column('calendar_rrule', True)
def __register__(cls, module_name): cursor = Transaction().cursor reference_exists = True if TableHandler.table_exist(cursor, cls._table): table = TableHandler(cursor, cls, module_name) reference_exists = table.column_exist('reference') super(SaleOpportunity, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.8: make party not required and add reference as # required table.not_null_action('party', action='remove') if not reference_exists: cursor.execute('UPDATE "' + cls._table + '" SET reference=id WHERE ' 'reference IS NULL') table.not_null_action('reference', action='add')
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.8: new field company table = TableHandler(cursor, cls, module_name) company_exist = table.column_exist('company') super(Statement, cls).__register__(module_name) # Migration from 1.8: fill new field company if not company_exist: offset = 0 limit = cursor.IN_MAX statements = True while statements: statements = cls.search([], offset=offset, limit=limit) offset += limit for statement in statements: cls.write([statement], { 'company': statement.journal.company.id, }) table = TableHandler(cursor, cls, module_name) table.not_null_action('company', action='add')