Skip to content

Commit

Permalink
fix import script (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarmo888 authored and tonyofbyteball committed Jun 1, 2019
1 parent e5aa8d0 commit e95ba4e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ A bot that attests Steem account and reputation

# Setup
* Run `npm install` to install node modules.
* Run `node db_import.js` to import `db.sql` into the database and appling database migrations.
* Run `node attestation.js` first time to generate keys.
* Run `node db_import.js` to import `db.sql` into the database.
* Configure `admin_email`, `from_email`, `site`, `steemconnectApp` and `salt` values in new conf.json file (desktopApp.getAppDataDir() folder). Read more about other configuration options [there](https://github.com/byteball/headless-obyte#customize).
* Send bytes to `== distribution address`, which is displayed in logs, it is for rewards and referral bonuses.
* Run `node attestation.js` again.
Expand Down
29 changes: 16 additions & 13 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TABLE users (
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (device_address) REFERENCES correspondent_devices(device_address)
);

-- query separator
CREATE TABLE receiving_addresses (
receiving_address CHAR(32) NOT NULL PRIMARY KEY,
device_address CHAR(33) NOT NULL,
Expand All @@ -22,18 +22,21 @@ CREATE TABLE receiving_addresses (
FOREIGN KEY (device_address) REFERENCES correspondent_devices(device_address),
FOREIGN KEY (receiving_address) REFERENCES my_addresses(address)
);
-- query separator
CREATE INDEX byReceivingAddress ON receiving_addresses(receiving_address);
-- query separator
CREATE INDEX ra_byUserAddress ON receiving_addresses(user_address);
-- query separator
CREATE INDEX byUsername ON receiving_addresses(username);

-- query separator
CREATE TABLE transactions (
transaction_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
receiving_address CHAR(32) NOT NULL,
proof_type VARCHAR(10) CHECK (proof_type IN('payment', 'signature')) NOT NULL,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (receiving_address) REFERENCES receiving_addresses(receiving_address)
);

-- query separator
CREATE TABLE accepted_payments (
transaction_id INTEGER NOT NULL PRIMARY KEY,
receiving_address CHAR(32) NOT NULL,
Expand All @@ -45,9 +48,9 @@ CREATE TABLE accepted_payments (
confirmation_date TIMESTAMP NULL,
FOREIGN KEY (receiving_address) REFERENCES receiving_addresses(receiving_address),
FOREIGN KEY (transaction_id) REFERENCES transactions(transaction_id)
-- FOREIGN KEY (payment_unit) REFERENCES units(unit) ON DELETE CASCADE
-- FOREIGN KEY (payment_unit) REFERENCES units(unit) ON DELETE CASCADE
);

-- query separator
CREATE TABLE rejected_payments (
rejected_payment_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
receiving_address CHAR(32) NOT NULL,
Expand All @@ -57,19 +60,19 @@ CREATE TABLE rejected_payments (
payment_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
error TEXT NOT NULL,
FOREIGN KEY (receiving_address) REFERENCES receiving_addresses(receiving_address)
-- FOREIGN KEY (payment_unit) REFERENCES units(unit) ON DELETE CASCADE
-- FOREIGN KEY (payment_unit) REFERENCES units(unit) ON DELETE CASCADE
);

-- query separator
CREATE TABLE signed_messages (
transaction_id INTEGER NOT NULL PRIMARY KEY,
user_address CHAR(32) NOT NULL,
signed_message TEXT NOT NULL,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (transaction_id) REFERENCES transactions(transaction_id)
);
-- query separator
CREATE INDEX sm_byUserAddress ON signed_messages(user_address);


-- query separator
CREATE TABLE attestation_units (
transaction_id INTEGER NOT NULL,
attestation_unit CHAR(44) NULL UNIQUE,
Expand All @@ -78,15 +81,15 @@ CREATE TABLE attestation_units (
FOREIGN KEY (transaction_id) REFERENCES transactions(transaction_id),
FOREIGN KEY (attestation_unit) REFERENCES units(unit)
);

-- query separator
CREATE TABLE contracts (
user_address CHAR(32) NOT NULL PRIMARY KEY,
contract_address CHAR(32) NOT NULL UNIQUE,
contract_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
contract_vesting_date TIMESTAMP NOT NULL,
FOREIGN KEY (contract_address) REFERENCES shared_addresses(shared_address)
);

-- query separator
CREATE TABLE link_referrals (
referring_user_address CHAR(32) NOT NULL, -- must be attested
device_address CHAR(33) NOT NULL,
Expand All @@ -95,7 +98,7 @@ CREATE TABLE link_referrals (
PRIMARY KEY (device_address, referring_user_address, type),
FOREIGN KEY (device_address) REFERENCES correspondent_devices(device_address)
);

-- query separator
CREATE TABLE reward_units (
transaction_id INTEGER NOT NULL PRIMARY KEY,
device_address CHAR(33) NOT NULL UNIQUE,
Expand All @@ -109,7 +112,7 @@ CREATE TABLE reward_units (
FOREIGN KEY (transaction_id) REFERENCES transactions(transaction_id),
FOREIGN KEY (reward_unit) REFERENCES units(unit)
);

-- query separator
CREATE TABLE referral_reward_units (
transaction_id INTEGER NOT NULL PRIMARY KEY,
user_address CHAR(32) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion db_import.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*jslint node: true */
'use strict';
const fs = require('fs');
const db = require('byteballcore/db.js');
const db = require('ocore/db.js');

let db_sql = fs.readFileSync('db.sql', 'utf8');
db_sql.split('-- query separator').forEach(function(sql) {
Expand Down

0 comments on commit e95ba4e

Please sign in to comment.