Skip to content

Commit

Permalink
Migration fix for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
physcom committed Oct 26, 2023
1 parent 08d98b3 commit 97f4464
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 51 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ dependencies {

// DB
implementation('org.flywaydb:flyway-core')
//implementation('com.h2database:h2')
implementation('org.xerial:sqlite-jdbc')
implementation('com.github.gwenn:sqlite-dialect:0.1.0')
implementation("org.xerial:sqlite-jdbc:3.36.0.3")
implementation("com.github.gwenn:sqlite-dialect:0.1.2")


// Utils
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = 'open-chain'

//include('frontend')
include('frontend')
includeBuild('./chain-kotlin-sdk')
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import io.openfuture.chain.network.message.core.TransferTransactionMessage
import io.openfuture.chain.rpc.domain.transaction.request.TransferTransactionRequest
import javax.persistence.Embedded
import javax.persistence.Entity
import javax.persistence.PrimaryKeyJoinColumn
import javax.persistence.Table

@Entity
@Table(name = "u_transfer_transactions")
@PrimaryKeyJoinColumn(name = "id")
class UnconfirmedTransferTransaction(
timestamp: Long,
fee: Long,
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application-chain-1.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ spring.datasource.url=jdbc:sqlite:./db/chain_1
spring.datasource.username=admin
spring.datasource.password=admin
#spring.jpa.open-in-view=true
spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
#spring.jpa.hibernate.ddl-auto=update
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true

# Logging
logging.level.io.openfuture.chain=INFO
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-chain-2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ spring.datasource.url=jdbc:sqlite:./db/chain_2
spring.datasource.username=admin
spring.datasource.password=admin
#spring.jpa.open-in-view=true
spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect
#spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto=update

# Logging
logging.level.io.openfuture.chain=INFO
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-chain-3.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ spring.datasource.url=jdbc:sqlite:./db/chain_3
spring.datasource.username=admin
spring.datasource.password=admin
#spring.jpa.open-in-view=true
spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect
#spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto=update

# Logging
logging.level.io.openfuture.chain=INFO
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ spring.datasource.driverClassName=org.sqlite.JDBC
spring.datasource.url=jdbc:sqlite:./db/chain
spring.datasource.username=admin
spring.datasource.password=admin
spring.jpa.open-in-view=true
spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.open-in-view=true
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
#spring.jpa.hibernate.ddl-auto=update

# Logging
logging.level.io.openfuture.chain=INFO
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/db/migration/V1_1__table_seed_words.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE seed_words (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
id INTEGER PRIMARY KEY,
ind INTEGER NOT NULL UNIQUE,
value VARCHAR NOT NULL UNIQUE
);
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/db/migration/V1_2__table_blocks.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE blocks (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
timestamp BIGINT NOT NULL,
height BIGINT NOT NULL,
id INTEGER PRIMARY KEY,
timestamp INTEGER NOT NULL,
height INTEGER NOT NULL,
previous_hash VARCHAR NOT NULL,
hash VARCHAR NOT NULL,
signature VARCHAR NOT NULL,
Expand All @@ -16,22 +16,22 @@ CREATE UNIQUE INDEX blocks_height
--

CREATE TABLE main_blocks (
id BIGINT PRIMARY KEY REFERENCES blocks,
id INTEGER PRIMARY KEY REFERENCES blocks,
transaction_merkle_hash VARCHAR NOT NULL,
state_merkle_hash VARCHAR NOT NULL,
receipt_merkle_hash VARCHAR NOT NULL
);
--
CREATE TABLE genesis_blocks (
id BIGINT PRIMARY KEY REFERENCES blocks,
epoch_index BIGINT NOT NULL
id INTEGER PRIMARY KEY REFERENCES blocks,
epoch_index INTEGER NOT NULL
);
--
CREATE INDEX genesis_blocks_epoch_index
ON genesis_blocks (epoch_index);
--
CREATE TABLE delegate2genesis (
public_key VARCHAR NOT NULL,
genesis_id BIGINT NOT NULL REFERENCES genesis_blocks,
genesis_id INTEGER NOT NULL REFERENCES genesis_blocks,
PRIMARY KEY (public_key, genesis_id)
);
40 changes: 20 additions & 20 deletions src/main/resources/db/migration/V1_3__table_transactions.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
CREATE TABLE transactions (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
timestamp BIGINT NOT NULL,
fee BIGINT NOT NULL,
id INTEGER PRIMARY KEY,
timestamp INTEGER NOT NULL,
fee INTEGER NOT NULL,
sender_address VARCHAR NOT NULL,
hash VARCHAR NOT NULL,
signature VARCHAR NOT NULL,
sender_key VARCHAR NOT NULL,
block_id BIGINT NOT NULL REFERENCES main_blocks
block_id INTEGER NOT NULL REFERENCES main_blocks
);
--
CREATE UNIQUE INDEX transaction_hash
Expand All @@ -16,8 +16,8 @@ CREATE INDEX transaction_sender_address
ON transactions (sender_address);
--
CREATE TABLE transfer_transactions (
id BIGINT PRIMARY KEY REFERENCES transactions,
amount BIGINT NOT NULL,
id INTEGER PRIMARY KEY REFERENCES transactions,
amount INTEGER NOT NULL,
recipient_address VARCHAR,
data VARCHAR
);
Expand All @@ -26,25 +26,25 @@ CREATE INDEX transfer_transaction_recipient_address
ON transfer_transactions (recipient_address);
--
CREATE TABLE reward_transactions (
id BIGINT PRIMARY KEY REFERENCES transactions,
reward BIGINT NOT NULL,
id INTEGER PRIMARY KEY REFERENCES transactions,
reward INTEGER NOT NULL,
recipient_address VARCHAR NOT NULL
);
--
CREATE INDEX reward_transactions_recipient_address
ON reward_transactions (recipient_address);
--
CREATE TABLE delegate_transactions (
id BIGINT PRIMARY KEY REFERENCES transactions,
id INTEGER PRIMARY KEY REFERENCES transactions,
delegate_key VARCHAR NOT NULL,
amount BIGINT NOT NULL
amount INTEGER NOT NULL
);
--
CREATE UNIQUE INDEX delegate_transactions_delegate_key
ON delegate_transactions (delegate_key);
--
CREATE TABLE vote_types (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
id INTEGER PRIMARY KEY,
key VARCHAR NOT NULL UNIQUE
);

Expand All @@ -53,7 +53,7 @@ VALUES (1, 'FOR'),
(2, 'AGAINST');
--
CREATE TABLE vote_transactions (
id BIGINT PRIMARY KEY REFERENCES transactions,
id INTEGER PRIMARY KEY REFERENCES transactions,
vote_type_id INTEGER NOT NULL REFERENCES vote_types,
delegate_key VARCHAR NOT NULL
);
Expand All @@ -65,9 +65,9 @@ CREATE INDEX vote_transactions_delegate_key

-- UNCONFIRMED TABLES
CREATE TABLE u_transactions (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
timestamp BIGINT NOT NULL,
fee BIGINT NOT NULL,
id INTEGER PRIMARY KEY,
timestamp INTEGER NOT NULL,
fee INTEGER NOT NULL,
sender_address VARCHAR NOT NULL,
hash VARCHAR NOT NULL,
signature VARCHAR NOT NULL,
Expand All @@ -84,23 +84,23 @@ CREATE INDEX u_transactions_fee
ON u_transactions (fee);
--
CREATE TABLE u_transfer_transactions (
id BIGINT PRIMARY KEY REFERENCES u_transactions,
amount BIGINT NOT NULL,
id INTEGER PRIMARY KEY REFERENCES u_transactions,
amount INTEGER NOT NULL,
recipient_address VARCHAR,
data VARCHAR
);
--
CREATE TABLE u_delegate_transactions (
id BIGINT PRIMARY KEY REFERENCES u_transactions,
id INTEGER PRIMARY KEY REFERENCES u_transactions,
delegate_key VARCHAR NOT NULL,
amount BIGINT NOT NULL
amount INTEGER NOT NULL
);
--
CREATE UNIQUE INDEX u_delegate_transactions_delegate_key
ON u_delegate_transactions (delegate_key);
--
CREATE TABLE u_vote_transactions (
id BIGINT PRIMARY KEY REFERENCES u_transactions,
id INTEGER PRIMARY KEY REFERENCES u_transactions,
vote_type_id INTEGER NOT NULL REFERENCES vote_types,
delegate_key VARCHAR NOT NULL
);
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/db/migration/V1_4__table_states.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE states (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
id INTEGER PRIMARY KEY,
address VARCHAR NOT NULL,
hash VARCHAR NOT NULL
);
Expand All @@ -8,15 +8,15 @@ CREATE UNIQUE INDEX states_address
ON states (address);
--
CREATE TABLE account_states (
id BIGINT PRIMARY KEY REFERENCES states,
balance BIGINT NOT NULL,
id INTEGER PRIMARY KEY REFERENCES states,
balance INTEGER NOT NULL,
vote_for VARCHAR,
storage VARCHAR
);
--
CREATE TABLE delegate_states (
id BIGINT PRIMARY KEY REFERENCES states,
rating BIGINT NOT NULL,
id INTEGER PRIMARY KEY REFERENCES states,
rating INTEGER NOT NULL,
wallet_address VARCHAR NOT NULL,
create_date BIGINT NOT NULL
create_date INTEGER NOT NULL
);
2 changes: 1 addition & 1 deletion src/main/resources/db/migration/V1_5__table_contracts.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE contracts (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
id INTEGER PRIMARY KEY,
address VARCHAR NOT NULL,
owner VARCHAR NOT NULL,
bytecode VARCHAR NOT NULL,
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/db/migration/V1_6__table_receipts.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CREATE TABLE receipts (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
id INTEGER PRIMARY KEY,
transaction_hash VARCHAR NOT NULL,
result VARCHAR NOT NULL,
hash VARCHAR NOT NULL,
block_id BIGINT NOT NULL REFERENCES main_blocks
block_id INTEGER NOT NULL REFERENCES main_blocks
);
--
CREATE UNIQUE INDEX receipts_transaction_hash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE temporary_blocks
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
height BIGINT UNIQUE NOT NULL,
id INTEGER PRIMARY KEY,
height INTEGER UNIQUE NOT NULL,
block VARCHAR NOT NULL
);

0 comments on commit 97f4464

Please sign in to comment.