SQL migration

This commit is contained in:
kexkey
2018-12-13 14:41:26 -05:00
parent ed9d4ba7f9
commit 36dfc92985
8 changed files with 117 additions and 49 deletions

View File

@@ -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.

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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");

View File

@@ -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

View File

@@ -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");

View File

@@ -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