Skip to content

Commit ad37a9e

Browse files
committed
refactored the class sqlthread with all version tests
1 parent 230d0ed commit ad37a9e

File tree

5 files changed

+177
-339
lines changed

5 files changed

+177
-339
lines changed

src/class_sqlThread.py

Lines changed: 2 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ def connection_build():
4444
return conn, cur
4545

4646

47-
def versioning(self):
48-
"""
49-
Run mirgations with respect to versions
50-
"""
51-
def wrapper(*args):
52-
"""
53-
Run SQL and mocking DB for versions
54-
"""
55-
self = args[0]
56-
func_name = func.__name__
57-
version = func_name.rsplit('_', 1)[-1]
58-
self.run_migrations(version)
59-
return func(*args) # <-- use (self, ...)
60-
func = self
61-
return wrapper
62-
63-
6447
class UpgradeDB(object):
6548
"""
6649
Upgrade Db with respect to versions
@@ -110,17 +93,6 @@ def run_migrations(self, file_name):
11093
'ERROR trying to create database file (message.dat). Error message: %s\n' % str(err))
11194
os._exit(0)
11295

113-
# @versioning
114-
# def upgrade_schema_data_1(self): # pylint: disable=Method-could-be-a-function, R0201
115-
# """inventory
116-
# For version 1 and 3
117-
# Add a new column to the inventory table to store tags.
118-
# """
119-
#
120-
# logger.debug(
121-
# 'In messages.dat database, adding tag field to'
122-
# ' the inventory table.')
123-
12496
def upgrade_to_latest(self, cur, conn):
12597
"""
12698
Initialise upgrade level
@@ -134,6 +106,8 @@ def upgrade_to_latest(self, cur, conn):
134106

135107
# call upgrading level in loop
136108
for l in range(self.current_level, self.max_level):
109+
if int(l) == 3:
110+
continue
137111
self.upgrade_one_level(l)
138112
self.run_migrations(l)
139113

@@ -145,126 +119,6 @@ def upgrade_schema_data_level(self, level):
145119
parameters = (level + 1,)
146120
self.cur.execute(item, parameters)
147121

148-
# @versioning
149-
# def upgrade_schema_data_2(self): # pylint: disable=Method-could-be-a-function, R0201
150-
# """
151-
# For version 2
152-
# Let's get rid of the first20bytesofencryptedmessage field in the inventory table.
153-
# """
154-
#
155-
# logger.debug(
156-
# 'In messages.dat database, removing an obsolete field from'
157-
# ' the inventory table.')
158-
#
159-
# def upgrade_schema_data_3(self): # pylint: disable=Method-could-be-a-function, R0201
160-
# """
161-
# For version 3
162-
# Call method for version 1
163-
# """
164-
#
165-
# self.upgrade_schema_data_1()
166-
#
167-
# @versioning
168-
# def upgrade_schema_data_4(self): # pylint: disable=Method-could-be-a-function, R0201
169-
# """
170-
# For version 4
171-
# Add a new column to the pubkeys table to store the address version.
172-
# We're going to trash all of our pubkeys and let them be redownloaded.
173-
# """
174-
#
175-
# @versioning
176-
# def upgrade_schema_data_5(self): # pylint: disable=Method-could-be-a-function, R0201
177-
# """
178-
# For version 5
179-
# Add a new table: objectprocessorqueue with which to hold objects
180-
# That have yet to be processed if the user shuts down Bitmessage.
181-
# """
182-
#
183-
# @versioning
184-
# def upgrade_schema_data_6(self): # pylint: disable=Method-could-be-a-function, R0201
185-
# """
186-
# For version 6
187-
# Changes related to protocol v3
188-
# In table inventory and objectprocessorqueue, objecttype is now
189-
# an integer (it was a human-friendly string previously)
190-
# """
191-
#
192-
# logger.debug(
193-
# 'In messages.dat database, dropping and recreating'
194-
# ' the inventory table.')
195-
#
196-
# logger.debug(
197-
# 'Finished dropping and recreating the inventory table.')
198-
#
199-
# @versioning
200-
# def upgrade_schema_data_7(self): # pylint: disable=Method-could-be-a-function, R0201
201-
# """
202-
# For version 7
203-
# The format of data stored in the pubkeys table has changed. Let's
204-
# clear it, and the pubkeys from inventory, so that they'll
205-
# be re-downloaded.
206-
# """
207-
#
208-
# logger.debug(
209-
# 'In messages.dat database, clearing pubkeys table'
210-
# ' because the data format has been updated.')
211-
#
212-
# logger.debug('Finished clearing currently held pubkeys.')
213-
#
214-
# @versioning
215-
# def upgrade_schema_data_8(self): # pylint: disable=Method-could-be-a-function, R0201
216-
# """
217-
# For version 8
218-
# Add a new column to the inbox table to store the hash of
219-
# the message signature. We'll use this as temporary message UUID
220-
# in order to detect duplicates.
221-
# """
222-
#
223-
# logger.debug(
224-
# 'In messages.dat database, adding sighash field to'
225-
# ' the inbox table.')
226-
#
227-
# @versioning
228-
# def upgrade_schema_data_9(self): # pylint: disable=Method-could-be-a-function, R0201
229-
# """
230-
# For version 9
231-
# We'll also need a `sleeptill` field and a `ttl` field. Also we
232-
# can combine the pubkeyretrynumber and msgretrynumber into one.
233-
# """
234-
#
235-
# logger.info(
236-
# 'In messages.dat database, making TTL-related changes:'
237-
# ' combining the pubkeyretrynumber and msgretrynumber'
238-
# ' fields into the retrynumber field and adding the'
239-
# ' sleeptill and ttl fields...')
240-
#
241-
# logger.info('In messages.dat database, finished making TTL-related changes.')
242-
# logger.debug('In messages.dat database, adding address field to the pubkeys table.')
243-
#
244-
# # We're going to have to calculate the address for each row in the pubkeys
245-
# # table. Then we can take out the hash field.
246-
# self.cur.execute('''ALTER TABLE pubkeys ADD address text DEFAULT '' ''')
247-
#
248-
# # replica for loop to update hashed address
249-
# self.cur.execute('''UPDATE pubkeys SET address=(enaddr(pubkeys.addressversion, 1, hash)); ''')
250-
#
251-
# self.run_migrations("9_1")
252-
#
253-
# logger.debug(
254-
# 'In messages.dat database, done adding address field to the pubkeys table'
255-
# ' and removing the hash field.')
256-
#
257-
# @versioning
258-
# def upgrade_schema_data_10(self): # pylint: disable=Method-could-be-a-function, R0201
259-
# """
260-
# For version 10
261-
# Update the address colunm to unique in addressbook table
262-
# """
263-
#
264-
# logger.debug(
265-
# 'In messages.dat database, updating address column to UNIQUE'
266-
# ' in the addressbook table.')
267-
268122

269123
class sqlThread(threading.Thread, UpgradeDB):
270124
"""A thread for all SQL operations"""

src/sql/init_version_9.sql

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, m
3030
-- -- Drope table `sent`
3131
-- --
3232

33-
DROP TABLE sent;
33+
DROP TABLE sent;
3434

3535

3636
-- --
@@ -71,4 +71,71 @@ INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message,
7171
-- -- Drop table `sent`
7272
-- --
7373

74-
DROP TABLE sent_backup;
74+
DROP TABLE sent_backup;
75+
76+
-- --
77+
-- -- Update Table `pubkeys`
78+
-- -- We're going to have to calculate the address for each row in the pubkeys
79+
-- -- table. Then we can take out the hash field.
80+
-- --
81+
82+
ALTER TABLE pubkeys ADD address text DEFAULT '' ;
83+
84+
-- --
85+
-- -- Update Table `pubkeys`
86+
-- -- replica for loop to update hashed address
87+
-- --
88+
89+
UPDATE pubkeys SET address=(enaddr(pubkeys.addressversion, 1, hash));
90+
91+
-- --
92+
-- -- Table structure for table `pubkeys_backup`
93+
-- --
94+
95+
CREATE TEMPORARY TABLE `pubkeys_backup` (
96+
`address` text DEFAULT NULL,
97+
`addressversion` int DEFAULT NULL,
98+
`transmitdata` blob DEFAULT NULL,
99+
`time` int DEFAULT NULL,
100+
`usedpersonally` text DEFAULT NULL,
101+
UNIQUE(address) ON CONFLICT REPLACE
102+
) ;
103+
104+
105+
-- --
106+
-- -- Dumping data for table `pubkeys_backup`
107+
-- --
108+
109+
INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;
110+
111+
112+
-- --
113+
-- -- Drope table `pubkeys`
114+
-- --
115+
116+
DROP TABLE pubkeys;
117+
118+
-- --
119+
-- -- Table structure for table `pubkeys`
120+
-- --
121+
122+
CREATE TABLE `pubkeys` (
123+
`address` text DEFAULT NULL,
124+
`addressversion` int DEFAULT NULL,
125+
`transmitdata` blob DEFAULT NULL,
126+
`time` int DEFAULT NULL,
127+
`usedpersonally` text DEFAULT NULL,
128+
UNIQUE(address) ON CONFLICT REPLACE
129+
) ;
130+
131+
-- --
132+
-- -- Dumping data for table `pubkeys`
133+
-- --
134+
135+
INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;
136+
137+
-- --
138+
-- -- Dropping table `pubkeys_backup`
139+
-- --
140+
141+
DROP TABLE pubkeys_backup;

src/sql/init_version_9_1.sql

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/tests/sql/init_version_9_1.sql

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)