diff --git a/doc/INSTALL-MANUALLY.md b/doc/INSTALL-MANUALLY.md index b50e090..475bf53 100644 --- a/doc/INSTALL-MANUALLY.md +++ b/doc/INSTALL-MANUALLY.md @@ -1,5 +1,13 @@ # This README file can be used if you want to install manually. This is the old documentation before there was the installer. +## Upgrading + +Your proxy's database won't be lost. Migration scripts are taking care of automatically migrating the database when starting the proxy. + +``` +proxy_docker/app/data/sqlmigrate* +``` + # Cyphernode Indirection layer between client and Bitcoin-related services. diff --git a/doc/INSTALL.md b/doc/INSTALL.md index fa55784..75fc6bb 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -20,6 +20,14 @@ Or you can simply run this magic command to start setup and installation: curl -fsSL https://raw.githubusercontent.com/SatoshiPortal/cyphernode/master/dist/setup.sh -o setup_cyphernode.sh && chmod +x setup_cyphernode.sh && ./setup_cyphernode.sh ``` +## Upgrading + +Your proxy's database won't be lost. Migration scripts are taking care of automatically migrating the database when starting the proxy. + +``` +proxy_docker/app/data/sqlmigrate* +``` + ## Manually test your installation through the Gatekeeper If you need the authorization header to copy/paste in another tool, put your API ID (id=) and API key (k=) in the following command: diff --git a/proxy_docker/Dockerfile.amd64 b/proxy_docker/Dockerfile.amd64 index 0cbabd7..74823b1 100644 --- a/proxy_docker/Dockerfile.amd64 +++ b/proxy_docker/Dockerfile.amd64 @@ -24,33 +24,34 @@ RUN apk add --update --no-cache \ curl \ su-exec -COPY app/script/callbacks_job.sh ${HOME}/callbacks_job.sh -COPY app/script/blockchainrpc.sh ${HOME}/blockchainrpc.sh -COPY app/script/call_lightningd.sh ${HOME}/call_lightningd.sh -COPY app/script/bitcoin.sh ${HOME}/bitcoin.sh -COPY app/script/ots.sh ${HOME}/ots.sh -COPY app/script/requesthandler.sh ${HOME}/requesthandler.sh -COPY app/script/watchrequest.sh ${HOME}/watchrequest.sh -COPY app/script/walletoperations.sh ${HOME}/walletoperations.sh -COPY app/script/confirmation.sh ${HOME}/confirmation.sh -COPY app/script/startproxy.sh ${HOME}/startproxy.sh -COPY app/script/trace.sh ${HOME}/trace.sh -COPY app/script/sendtobitcoinnode.sh ${HOME}/sendtobitcoinnode.sh -COPY app/script/responsetoclient.sh ${HOME}/responsetoclient.sh -COPY app/script/importaddress.sh ${HOME}/importaddress.sh -COPY app/script/sql.sh ${HOME}/sql.sh -COPY app/data/watching.sql ${HOME}/watching.sql -COPY app/script/computefees.sh ${HOME}/computefees.sh -COPY app/script/unwatchrequest.sh ${HOME}/unwatchrequest.sh -COPY app/script/getactivewatches.sh ${HOME}/getactivewatches.sh -COPY app/script/manage_missed_conf.sh ${HOME}/manage_missed_conf.sh -COPY app/script/tests.sh ${HOME}/tests.sh -COPY app/script/tests-cb.sh ${HOME}/tests-cb.sh -COPY --from=cyphernode/clightning:v0.6.2 /usr/bin/lightning-cli ${HOME}/lightning-cli +COPY app/data/cyphernode.sql ${HOME} +COPY app/data/sqlmigrate* ${HOME} +COPY app/script/callbacks_job.sh ${HOME} +COPY app/script/blockchainrpc.sh ${HOME} +COPY app/script/call_lightningd.sh ${HOME} +COPY app/script/bitcoin.sh ${HOME} +COPY app/script/ots.sh ${HOME} +COPY app/script/requesthandler.sh ${HOME} +COPY app/script/watchrequest.sh ${HOME} +COPY app/script/walletoperations.sh ${HOME} +COPY app/script/confirmation.sh ${HOME} +COPY app/script/startproxy.sh ${HOME} +COPY app/script/trace.sh ${HOME} +COPY app/script/sendtobitcoinnode.sh ${HOME} +COPY app/script/responsetoclient.sh ${HOME} +COPY app/script/importaddress.sh ${HOME} +COPY app/script/sql.sh ${HOME} +COPY app/script/computefees.sh ${HOME} +COPY app/script/unwatchrequest.sh ${HOME} +COPY app/script/getactivewatches.sh ${HOME} +COPY app/script/manage_missed_conf.sh ${HOME} +COPY app/script/tests.sh ${HOME} +COPY app/script/tests-cb.sh ${HOME} +COPY --from=cyphernode/clightning:v0.6.2 /usr/bin/lightning-cli ${HOME} WORKDIR ${HOME} -RUN chmod +x startproxy.sh requesthandler.sh lightning-cli \ +RUN chmod +x startproxy.sh requesthandler.sh lightning-cli sqlmigrate*.sh \ && chmod o+w . \ && mkdir db diff --git a/proxy_docker/Dockerfile.arm32v6 b/proxy_docker/Dockerfile.arm32v6 index 0a4f66c..7fa641e 100644 --- a/proxy_docker/Dockerfile.arm32v6 +++ b/proxy_docker/Dockerfile.arm32v6 @@ -20,33 +20,34 @@ RUN apk add --update --no-cache \ curl \ su-exec -COPY app/script/callbacks_job.sh ${HOME}/callbacks_job.sh -COPY app/script/blockchainrpc.sh ${HOME}/blockchainrpc.sh -COPY app/script/call_lightningd.sh ${HOME}/call_lightningd.sh -COPY app/script/bitcoin.sh ${HOME}/bitcoin.sh -COPY app/script/ots.sh ${HOME}/ots.sh -COPY app/script/requesthandler.sh ${HOME}/requesthandler.sh -COPY app/script/watchrequest.sh ${HOME}/watchrequest.sh -COPY app/script/walletoperations.sh ${HOME}/walletoperations.sh -COPY app/script/confirmation.sh ${HOME}/confirmation.sh -COPY app/script/startproxy.sh ${HOME}/startproxy.sh -COPY app/script/trace.sh ${HOME}/trace.sh -COPY app/script/sendtobitcoinnode.sh ${HOME}/sendtobitcoinnode.sh -COPY app/script/responsetoclient.sh ${HOME}/responsetoclient.sh -COPY app/script/importaddress.sh ${HOME}/importaddress.sh -COPY app/script/sql.sh ${HOME}/sql.sh -COPY app/data/watching.sql ${HOME}/watching.sql -COPY app/script/computefees.sh ${HOME}/computefees.sh -COPY app/script/unwatchrequest.sh ${HOME}/unwatchrequest.sh -COPY app/script/getactivewatches.sh ${HOME}/getactivewatches.sh -COPY app/script/manage_missed_conf.sh ${HOME}/manage_missed_conf.sh -COPY app/script/tests.sh ${HOME}/tests.sh -COPY app/script/tests-cb.sh ${HOME}/tests-cb.sh -COPY --from=cyphernode/clightning:v0.6.2 /usr/bin/lightning-cli ${HOME}/lightning-cli +COPY app/data/cyphernode.sql ${HOME} +COPY app/data/sqlmigrate* ${HOME} +COPY app/script/callbacks_job.sh ${HOME} +COPY app/script/blockchainrpc.sh ${HOME} +COPY app/script/call_lightningd.sh ${HOME} +COPY app/script/bitcoin.sh ${HOME} +COPY app/script/ots.sh ${HOME} +COPY app/script/requesthandler.sh ${HOME} +COPY app/script/watchrequest.sh ${HOME} +COPY app/script/walletoperations.sh ${HOME} +COPY app/script/confirmation.sh ${HOME} +COPY app/script/startproxy.sh ${HOME} +COPY app/script/trace.sh ${HOME} +COPY app/script/sendtobitcoinnode.sh ${HOME} +COPY app/script/responsetoclient.sh ${HOME} +COPY app/script/importaddress.sh ${HOME} +COPY app/script/sql.sh ${HOME} +COPY app/script/computefees.sh ${HOME} +COPY app/script/unwatchrequest.sh ${HOME} +COPY app/script/getactivewatches.sh ${HOME} +COPY app/script/manage_missed_conf.sh ${HOME} +COPY app/script/tests.sh ${HOME} +COPY app/script/tests-cb.sh ${HOME} +COPY --from=cyphernode/clightning:v0.6.2 /usr/bin/lightning-cli ${HOME} WORKDIR ${HOME} -RUN chmod +x startproxy.sh requesthandler.sh lightning-cli \ +RUN chmod +x startproxy.sh requesthandler.sh lightning-cli sqlmigrate*.sh \ && chmod o+w . \ && mkdir db diff --git a/proxy_docker/app/data/watching.sql b/proxy_docker/app/data/cyphernode.sql similarity index 82% rename from proxy_docker/app/data/watching.sql rename to proxy_docker/app/data/cyphernode.sql index 0717ec4..48bb1ad 100644 --- a/proxy_docker/app/data/watching.sql +++ b/proxy_docker/app/data/cyphernode.sql @@ -63,3 +63,15 @@ CREATE TABLE stamp ( calledback INTEGER DEFAULT FALSE, inserted_ts INTEGER DEFAULT CURRENT_TIMESTAMP ); +CREATE INDEX idx_stamp_hash ON stamp (hash); +CREATE INDEX idx_stamp_calledback ON stamp (calledback); + +CREATE TABLE cyphernode_props ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + property TEXT, + value TEXT, + inserted_ts INTEGER DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX idx_cp_property ON cyphernode_props (property); + +INSERT INTO cyphernode_props (property, value) VALUES ("version", "0.1"); diff --git a/proxy_docker/app/data/sqlmigrate20181213_0-0.1.sh b/proxy_docker/app/data/sqlmigrate20181213_0-0.1.sh new file mode 100644 index 0000000..0b69b16 --- /dev/null +++ b/proxy_docker/app/data/sqlmigrate20181213_0-0.1.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +sqlite3 db/proxydb ".tables" | grep "stamp" > /dev/null +if [ "$?" -eq "1" ]; then + # stamp not there, we have to migrate + echo "Migrating database from v0 to v0.1..." + cat sqlmigrate20181213_0-0.1.sql | sqlite3 $DB_FILE +else + echo "Database v0 to v0.1 migration already done, skipping!" +fi diff --git a/proxy_docker/app/data/sqlmigrate20181213_0-0.1.sql b/proxy_docker/app/data/sqlmigrate20181213_0-0.1.sql new file mode 100644 index 0000000..4bc7f7b --- /dev/null +++ b/proxy_docker/app/data/sqlmigrate20181213_0-0.1.sql @@ -0,0 +1,23 @@ +PRAGMA foreign_keys = ON; + +CREATE TABLE stamp ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + hash TEXT UNIQUE, + callbackUrl TEXT, + requested INTEGER DEFAULT FALSE, + upgraded INTEGER DEFAULT FALSE, + calledback INTEGER DEFAULT FALSE, + inserted_ts INTEGER DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX idx_stamp_hash ON stamp (hash); +CREATE INDEX idx_stamp_calledback ON stamp (calledback); + +CREATE TABLE cyphernode_props ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + property TEXT, + value TEXT, + inserted_ts INTEGER DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX idx_cp_property ON cyphernode_props (property); + +INSERT INTO cyphernode_props (property, value) VALUES ("version", "0.1"); diff --git a/proxy_docker/app/script/startproxy.sh b/proxy_docker/app/script/startproxy.sh index ab367cc..eaec2e3 100644 --- a/proxy_docker/app/script/startproxy.sh +++ b/proxy_docker/app/script/startproxy.sh @@ -32,7 +32,12 @@ createCurlConfig() { if [ ! -e ${DB_FILE} ]; then echo "DB not found, creating..." - cat watching.sql | sqlite3 $DB_FILE + cat cyphernode.sql | sqlite3 $DB_FILE +else + echo "DB found, migrating..." + for script in sqlmigrate*.sh; do + sh $script + done fi chmod 0600 $DB_FILE