[backup/portable] properly write the eid numrange generator (the eid is no more a sequence)
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 26 Jan 2015 18:05:24 +0100
changeset 10196 20d56b1f035e
parent 10186 bc1f5faad60b
child 10197 7c732d2abbc1
[backup/portable] properly write the eid numrange generator (the eid is no more a sequence) Bump format version to 1.1. Related to #4870338
server/sources/native.py
--- a/server/sources/native.py	Thu Feb 05 15:40:07 2015 +0100
+++ b/server/sources/native.py	Mon Jan 26 18:05:24 2015 +0100
@@ -1586,6 +1586,9 @@
             for seq in self.get_sequences():
                 self.logger.info('processing sequence %s', seq)
                 self.write_sequence(archive, seq)
+            for numrange in self.get_numranges():
+                self.logger.info('processing numrange %s', numrange)
+                self.write_numrange(archive, numrange)
             for table in self.get_tables():
                 self.logger.info('processing table %s', table)
                 self.write_table(archive, table)
@@ -1616,12 +1619,16 @@
         return non_entity_tables + etype_tables + relation_tables
 
     def get_sequences(self):
+        return []
+
+    def get_numranges(self):
         return ['entities_id_seq']
 
     def write_metadata(self, archive):
-        archive.writestr('format.txt', '1.0')
+        archive.writestr('format.txt', '1.1')
         archive.writestr('tables.txt', '\n'.join(self.get_tables()))
         archive.writestr('sequences.txt', '\n'.join(self.get_sequences()))
+        archive.writestr('numranges.txt', '\n'.join(self.get_numranges()))
         versions = self._get_versions()
         versions_str = '\n'.join('%s %s' % (k, v)
                                  for k, v in versions)
@@ -1634,6 +1641,13 @@
         serialized = self._serialize(seq, columns, rows)
         archive.writestr('sequences/%s' % seq, serialized)
 
+    def write_numrange(self, archive, numrange):
+        sql = self.dbhelper.sql_numrange_current_state(numrange)
+        columns, rows_iterator = self._get_cols_and_rows(sql)
+        rows = list(rows_iterator)
+        serialized = self._serialize(numrange, columns, rows)
+        archive.writestr('numrange/%s' % numrange, serialized)
+
     def write_table(self, archive, table):
         nb_lines_sql = 'SELECT COUNT(*) FROM %s' % table
         self.cursor.execute(nb_lines_sql)