Skip to content

Refactor sqlthread #1760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/bmconfigparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from six import string_types
from six.moves import configparser

import state
from singleton import Singleton
try:
import state
from singleton import Singleton
except ImportError:
from . import state
from .singleton import Singleton

SafeConfigParser = configparser.SafeConfigParser

Expand Down
480 changes: 197 additions & 283 deletions src/class_sqlThread.py

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/helper_startup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"""
Startup operations.
"""
# pylint: disable=too-many-branches,too-many-statements

import logging
import os
import platform
import sys
import time
from distutils.version import StrictVersion

import sys
if sys.version_info[0] == 3:
from . import defaults
Expand All @@ -29,6 +25,8 @@
except ImportError:
get_plugin = None

# pylint: disable=too-many-branches,too-many-statements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a code quality only change? Then it should go into a separate PR.


logger = logging.getLogger('default')

Expand Down
Empty file added src/sql/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions src/sql/init_version_10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- --
-- -- Alter table `addressbook`
-- --

ALTER TABLE addressbook RENAME TO old_addressbook;


-- --
-- -- Table structure for table `addressbook`
-- --

CREATE TABLE `addressbook` (
`label` text NOT NULL,
`address` text NOT NULL,
UNIQUE(address) ON CONFLICT IGNORE
) ;

-- --
-- -- Table Query for `pubkeys_backup`
-- --

INSERT INTO addressbook SELECT label, address FROM old_addressbook;


-- --
-- -- Drop table `old_addressbook`
-- --

DROP TABLE old_addressbook;
55 changes: 55 additions & 0 deletions src/sql/init_version_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--
-- Temp Table structure for table `inventory_backup`
--

CREATE TEMP TABLE `inventory_backup` (
`hash` blob NOT NULL,
`objecttype` text DEFAULT NULL,
`streamnumber` int NOT NULL,
`receivedtime` int NOT NULL,
`payload` blob DEFAULT NULL,
-- `integer` integer NOT NULL,
-- `tag` blob DEFAULT NULL,
UNIQUE(hash) ON CONFLICT REPLACE
) ;

--
-- Dumping data for table `inventory_backup`
--

INSERT INTO `inventory_backup` SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;


--
-- Drop table `inventory`
--

DROP TABLE inventory;


--
-- Table structure for table `inventory`
--


CREATE TABLE `inventory` (
`hash` blob NOT NULL,
`objecttype` text DEFAULT NULL,
`streamnumber` int NOT NULL,
`receivedtime` int NOT NULL,
`payload` blob DEFAULT NULL,
UNIQUE(hash) ON CONFLICT REPLACE
) ;


--
-- Dumping data for table `inventory`
--

INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;

--
-- Drop data for table `inventory_backup`
--

DROP TABLE inventory_backup;
6 changes: 6 additions & 0 deletions src/sql/init_version_3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

--
-- Alter table `inventory`
--

ALTER TABLE inventory ADD tag blob DEFAULT '';
26 changes: 26 additions & 0 deletions src/sql/init_version_4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--
-- Drop Table `pubkeys`
--

DROP TABLE pubkeys;


--
-- Table structure for table `pubkeys`
--


CREATE TABLE `pubkeys` (
`hash` blob NOT NULL,
`addressversion` int DEFAULT NULL,
`transmitdata` blob NOT NULL,
`time` int NOT NULL,
`usedpersonally` text DEFAULT NULL,
UNIQUE(hash, addressversion) ON CONFLICT REPLACE
) ;

--
-- Drop from Table `pubkeys`
--

DELETE FROM inventory WHERE objecttype = 'pubkey';
17 changes: 17 additions & 0 deletions src/sql/init_version_5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--
-- Drop Table `knownnodes`
--

DROP TABLE knownnodes;


--
-- Table structure for table `objectprocessorqueue`
--


CREATE TABLE `objectprocessorqueue` (
`objecttype` text DEFAULT NULL,
`data` blob DEFAULT NULL,
UNIQUE(objecttype, data) ON CONFLICT REPLACE
) ;
39 changes: 39 additions & 0 deletions src/sql/init_version_6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- --
-- -- Drop table `inventory`
-- --

DROP TABLE inventory;


-- --
-- -- Table structure for table `inventory`
-- --


CREATE TABLE `inventory` (
`hash` blob NOT NULL,
`objecttype` int DEFAULT NULL,
`streamnumber` int NOT NULL,
`payload` blob NOT NULL,
`expirestime` integer DEFAULT NULL,
`tag` blob DEFAULT NULL,
UNIQUE(hash) ON CONFLICT REPLACE
) ;

-- --
-- -- Drop table `inventory`
-- --

DROP TABLE objectprocessorqueue;


-- --
-- -- Table structure for table `objectprocessorqueue`
-- --


CREATE TABLE `objectprocessorqueue` (
`objecttype` int DEFAULT NULL,
`data` blob DEFAULT NULL,
UNIQUE(objecttype, data) ON CONFLICT REPLACE
) ;
18 changes: 18 additions & 0 deletions src/sql/init_version_7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- --
-- -- Drop table `inventory`
-- --

DELETE FROM inventory WHERE objecttype = 1;

-- --
-- -- Drop table `pubkeys`
-- --

DELETE FROM pubkeys;


-- --
-- -- Update table `pubkeys`
-- --

UPDATE sent SET status='msgqueued' WHERE status='doingmsgpow' or status='badkey';
5 changes: 5 additions & 0 deletions src/sql/init_version_8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- --
-- -- Alter table `inbox`
-- --

ALTER TABLE inbox ADD sighash blob DEFAULT '';
141 changes: 141 additions & 0 deletions src/sql/init_version_9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
-- --
-- -- Table structure for table `sent_backup`
-- --


CREATE TEMPORARY TABLE `sent_backup` (
`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,
`lastactiontime` integer DEFAULT NULL,
`status` text DEFAULT NULL,
`retrynumber` integer DEFAULT NULL,
`folder` text DEFAULT NULL,
`encodingtype` int DEFAULT NULL
) ;


-- --
-- -- Dumping data for table `sent_backup`
-- --

INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;


-- --
-- -- Drope table `sent`
-- --

DROP TABLE sent;


-- --
-- -- Table structure for table `sent_backup`
-- --


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` int DEFAULT NULL,
`status` text DEFAULT NULL,
`retrynumber` integer DEFAULT NULL,
`folder` text DEFAULT NULL,
`encodingtype` int DEFAULT NULL,
`ttl` int DEFAULT NULL
) ;


-- --
-- -- Dumping data for table `sent`
-- --


INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;


--UPDATE pubkeys SET address= (select enaddr(?, ?, ?)", (addressVersion, 1, addressHash)) WHERE hash=?

-- --
-- -- Drop table `sent`
-- --

DROP TABLE sent_backup;

-- --
-- -- Update Table `pubkeys`
-- -- We're going to have to calculate the address for each row in the pubkeys
-- -- table. Then we can take out the hash field.
-- --

ALTER TABLE pubkeys ADD address text DEFAULT '' ;

-- --
-- -- Update Table `pubkeys`
-- -- replica for loop to update hashed address
-- --

UPDATE pubkeys SET address=(enaddr(pubkeys.addressversion, 1, hash));

-- --
-- -- Table structure for table `pubkeys_backup`
-- --

CREATE TEMPORARY TABLE `pubkeys_backup` (
`address` text DEFAULT NULL,
`addressversion` int DEFAULT NULL,
`transmitdata` blob DEFAULT NULL,
`time` int DEFAULT NULL,
`usedpersonally` text DEFAULT NULL,
UNIQUE(address) ON CONFLICT REPLACE
) ;


-- --
-- -- Dumping data for table `pubkeys_backup`
-- --

INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;


-- --
-- -- Drope table `pubkeys`
-- --

DROP TABLE pubkeys;

-- --
-- -- Table structure for table `pubkeys`
-- --

CREATE TABLE `pubkeys` (
`address` text DEFAULT NULL,
`addressversion` int DEFAULT NULL,
`transmitdata` blob DEFAULT NULL,
`time` int DEFAULT NULL,
`usedpersonally` text DEFAULT NULL,
UNIQUE(address) ON CONFLICT REPLACE
) ;

-- --
-- -- Dumping data for table `pubkeys`
-- --

INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;

-- --
-- -- Dropping table `pubkeys_backup`
-- --

DROP TABLE pubkeys_backup;
Loading