update test and thread
This commit is contained in:
parent
e41d200e81
commit
a3e52099bc
|
@ -51,11 +51,9 @@ class UpgradeDB():
|
||||||
|
|
||||||
def run_migrations(self, file):
|
def run_migrations(self, file):
|
||||||
try:
|
try:
|
||||||
# root_path = os.path.dirname(os.path.dirname(__file__))
|
|
||||||
sql_file = open(os.path.join(root_path, "src/sql/init_version_{}.sql".format(file)))
|
sql_file = open(os.path.join(root_path, "src/sql/init_version_{}.sql".format(file)))
|
||||||
sql_as_string = sql_file.read()
|
sql_as_string = sql_file.read()
|
||||||
self.cur.executescript(sql_as_string)
|
self.cur.executescript(sql_as_string)
|
||||||
# self.conn.commit()
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if str(err) == 'table inbox already exists':
|
if str(err) == 'table inbox already exists':
|
||||||
return "table inbox already exists"
|
return "table inbox already exists"
|
||||||
|
@ -210,13 +208,6 @@ class UpgradeDB():
|
||||||
item = '''UPDATE 'pubkeys' SET `hash`='87788778877887788787' where hash=''; '''
|
item = '''UPDATE 'pubkeys' SET `hash`='87788778877887788787' where hash=''; '''
|
||||||
self.cur.execute(item)
|
self.cur.execute(item)
|
||||||
|
|
||||||
# create_function
|
|
||||||
try:
|
|
||||||
self.conn.create_function("enaddr", 3, func=encodeAddress, deterministic=True)
|
|
||||||
except (TypeError, sqlite3.NotSupportedError) as err:
|
|
||||||
logger.error("Got error while pass deterministic in sqlite create function {}, Passing 3 params".format(err))
|
|
||||||
self.conn.create_function("enaddr", 3, encodeAddress)
|
|
||||||
|
|
||||||
# replica for loop to update hashed address
|
# replica for loop to update hashed address
|
||||||
self.cur.execute('''UPDATE pubkeys SET address=(select enaddr(pubkeys.addressversion, 1, hash)) WHERE hash=pubkeys.hash; ''')
|
self.cur.execute('''UPDATE pubkeys SET address=(select enaddr(pubkeys.addressversion, 1, hash)) WHERE hash=pubkeys.hash; ''')
|
||||||
|
|
||||||
|
@ -253,44 +244,54 @@ class sqlThread(threading.Thread, UpgradeDB):
|
||||||
|
|
||||||
self.cur.execute('PRAGMA secure_delete = true')
|
self.cur.execute('PRAGMA secure_delete = true')
|
||||||
|
|
||||||
try:
|
# call create_function for encode address
|
||||||
sql_file = open(os.path.join(root_path, "src/sql/{}.sql".format("run")))
|
self.create_function()
|
||||||
sql_as_string = sql_file.read()
|
|
||||||
self.cur.executescript(sql_as_string)
|
|
||||||
|
|
||||||
# self.cur.execute(
|
try:
|
||||||
# '''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,'''
|
# sql_file = open(os.path.join(root_path, "src/sql/{}.sql".format("run")))
|
||||||
# ''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
|
# sql_as_string = sql_file.read()
|
||||||
# ''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
|
# self.cur.executescript(sql_as_string)
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,'''
|
|
||||||
# ''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
|
|
||||||
# ''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE whitelist (label text, address text, enabled bool)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
|
|
||||||
# ''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,'''
|
|
||||||
# ''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''INSERT INTO subscriptions VALUES'''
|
|
||||||
# '''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
|
||||||
# self.cur.execute(
|
|
||||||
# '''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
|
||||||
# self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
# self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
||||||
# self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
# self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (int(time.time()),))
|
||||||
# int(time.time()),))
|
|
||||||
# self.cur.execute(
|
# self.cur.execute(
|
||||||
# '''CREATE TABLE objectprocessorqueue'''
|
# '''CREATE TABLE objectprocessorqueue'''
|
||||||
# ''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
|
# ''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
|
||||||
|
# self.conn.commit()
|
||||||
|
# logger.info('Created messages database file')
|
||||||
|
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,'''
|
||||||
|
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
|
||||||
|
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,'''
|
||||||
|
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
|
||||||
|
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE whitelist (label text, address text, enabled bool)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
|
||||||
|
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,'''
|
||||||
|
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''INSERT INTO subscriptions VALUES'''
|
||||||
|
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
||||||
|
self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
||||||
|
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
||||||
|
int(time.time()),))
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE objectprocessorqueue'''
|
||||||
|
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
logger.info('Created messages database file')
|
logger.info('Created messages database file')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -622,3 +623,12 @@ class sqlThread(threading.Thread, UpgradeDB):
|
||||||
|
|
||||||
helper_sql.sqlReturnQueue.put((self.cur.fetchall(), rowcount))
|
helper_sql.sqlReturnQueue.put((self.cur.fetchall(), rowcount))
|
||||||
# helper_sql.sqlSubmitQueue.task_done()
|
# helper_sql.sqlSubmitQueue.task_done()
|
||||||
|
|
||||||
|
def create_function(self):
|
||||||
|
# create_function
|
||||||
|
try:
|
||||||
|
self.conn.create_function("enaddr", 3, func=encodeAddress, deterministic=True)
|
||||||
|
except (TypeError, sqlite3.NotSupportedError) as err:
|
||||||
|
logger.error(
|
||||||
|
"Got error while pass deterministic in sqlite create function {}, Passing 3 params".format(err))
|
||||||
|
self.conn.create_function("enaddr", 3, encodeAddress)
|
||||||
|
|
196
src/sql/run.sql
196
src/sql/run.sql
|
@ -1,96 +1,126 @@
|
||||||
--
|
--
|
||||||
-- Temp Table structure for table `inventory_backup`
|
-- Table structure for table `inbox`
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE TEMP TABLE `inventory_backup` (
|
CREATE TABLE `inbox` (
|
||||||
`hash` blob NOT NULL,
|
`msgid` blob DEFAULT NULL,
|
||||||
`objecttype` text DEFAULT NULL,
|
`toaddress` text DEFAULT NULL,
|
||||||
`streamnumber` int NOT NULL,
|
`fromaddress` text DEFAULT NULL,
|
||||||
`receivedtime` int NOT NULL,
|
`subject` text DEFAULT NULL,
|
||||||
`payload` blob DEFAULT NULL,
|
`received` text DEFAULT NULL,
|
||||||
-- `integer` integer NOT NULL,
|
`message` text DEFAULT NULL,
|
||||||
-- `tag` blob DEFAULT NULL,
|
`folder` text DEFAULT NULL,
|
||||||
UNIQUE(hash) ON CONFLICT REPLACE
|
`encodingtype` int DEFAULT NULL,
|
||||||
) ;
|
`read` bool DEFAULT NULL,
|
||||||
|
`sighash` blob DEFAULT NULL,
|
||||||
|
UNIQUE(msgid) ON CONFLICT REPLACE
|
||||||
|
) ;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Dumping data for table `inventory_backup`
|
-- Table structure for table `sent`
|
||||||
--
|
--
|
||||||
|
|
||||||
INSERT INTO `inventory_backup` SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;
|
CREATE TABLE `sent` (
|
||||||
|
`msgid` blob DEFAULT NULL,
|
||||||
|
`toaddress` text DEFAULT NULL,
|
||||||
|
`toripe` blob DEFAULT NULL,
|
||||||
|
`fromaddress` text DEFAULT NULL,
|
||||||
|
`subject` text DEFAULT NULL,
|
||||||
|
`message` text DEFAULT NULL,
|
||||||
|
`ackdata` blob DEFAULT NULL,
|
||||||
|
`senttime` integer DEFAULT NULL,
|
||||||
|
`lastactiontime` integer DEFAULT NULL,
|
||||||
|
`sleeptill` integer DEFAULT NULL,
|
||||||
|
`status` text DEFAULT NULL,
|
||||||
|
`retrynumber` integer DEFAULT NULL,
|
||||||
|
`folder` text DEFAULT NULL,
|
||||||
|
`encodingtype` int DEFAULT NULL,
|
||||||
|
`ttl` int DEFAULT NULL
|
||||||
|
) ;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Drop table `inventory`
|
-- Table structure for table `subscriptions`
|
||||||
--
|
--
|
||||||
|
|
||||||
DROP TABLE inventory;
|
CREATE TABLE `subscriptions` (
|
||||||
|
`label` text DEFAULT NULL,
|
||||||
|
`address` text DEFAULT NULL,
|
||||||
|
`enabled` bool DEFAULT NULL
|
||||||
|
) ;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `inventory`
|
-- Table structure for table `addressbook`
|
||||||
--
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `addressbook` (
|
||||||
|
`label` text DEFAULT NULL,
|
||||||
|
`address` text DEFAULT NULL,
|
||||||
|
UNIQUE(address) ON CONFLICT IGNORE
|
||||||
|
) ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `blacklist`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `blacklist` (
|
||||||
|
`label` text DEFAULT NULL,
|
||||||
|
`address` text DEFAULT NULL,
|
||||||
|
`enabled` bool DEFAULT NULL
|
||||||
|
) ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `whitelist`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `whitelist` (
|
||||||
|
`label` text DEFAULT NULL,
|
||||||
|
`address` text DEFAULT NULL,
|
||||||
|
`enabled` bool DEFAULT NULL
|
||||||
|
) ;
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `inventory` (
|
--
|
||||||
`hash` blob NOT NULL,
|
-- Table structure for table `pubkeys`
|
||||||
`objecttype` text DEFAULT NULL,
|
--
|
||||||
`streamnumber` int NOT NULL,
|
|
||||||
`receivedtime` int NOT NULL,
|
CREATE TABLE `pubkeys` (
|
||||||
`payload` blob DEFAULT NULL,
|
`address` text DEFAULT NULL,
|
||||||
UNIQUE(hash) ON CONFLICT REPLACE
|
`addressversion` int DEFAULT NULL,
|
||||||
) ;
|
`transmitdata` blob DEFAULT NULL,
|
||||||
|
`time` int DEFAULT NULL,
|
||||||
|
`usedpersonally` text DEFAULT NULL,
|
||||||
|
UNIQUE(address) ON CONFLICT REPLACE
|
||||||
|
) ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `inventory`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `inventory` (
|
||||||
|
`hash` blob DEFAULT NULL,
|
||||||
|
`objecttype` int DEFAULT NULL,
|
||||||
|
`streamnumber` int DEFAULT NULL,
|
||||||
|
`payload` blob DEFAULT NULL,
|
||||||
|
`expirestime` integer DEFAULT NULL,
|
||||||
|
`tag` blob DEFAULT NULL,
|
||||||
|
UNIQUE(hash) ON CONFLICT REPLACE
|
||||||
|
) ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Insert data for table `subscriptions`
|
||||||
|
--
|
||||||
|
|
||||||
|
INSERT INTO subscriptions VALUES ('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Dumping data for table `inventory`
|
-- Table structure for table `settings`
|
||||||
--
|
--
|
||||||
|
|
||||||
INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;
|
CREATE TABLE `settings` (
|
||||||
|
`key` blob DEFAULT NULL,
|
||||||
--
|
`value` blob DEFAULT NULL,
|
||||||
-- Drop data for table `inventory_backup`
|
UNIQUE(key) ON CONFLICT REPLACE
|
||||||
--
|
) ;
|
||||||
|
|
||||||
DROP TABLE inventory_backup;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,'''
|
|
||||||
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
|
|
||||||
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,'''
|
|
||||||
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
|
|
||||||
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE whitelist (label text, address text, enabled bool)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
|
|
||||||
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,'''
|
|
||||||
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''INSERT INTO subscriptions VALUES'''
|
|
||||||
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
|
||||||
self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
|
||||||
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
|
||||||
int(time.time()),))
|
|
||||||
self.cur.execute(
|
|
||||||
'''CREATE TABLE objectprocessorqueue'''
|
|
||||||
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ from ..state import appdata
|
||||||
from ..helper_sql import sqlStoredProcedure, sql_ready
|
from ..helper_sql import sqlStoredProcedure, sql_ready
|
||||||
from ..class_sqlThread import (sqlThread, UpgradeDB)
|
from ..class_sqlThread import (sqlThread, UpgradeDB)
|
||||||
from ..addresses import encodeAddress
|
from ..addresses import encodeAddress
|
||||||
|
from .common import skip_python3
|
||||||
|
|
||||||
|
|
||||||
|
skip_python3()
|
||||||
|
|
||||||
|
|
||||||
class TestSqlThread(unittest.TestCase):
|
class TestSqlThread(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user