Skip to content
Permalink
Browse files
Merge pull request #12 from Izakey/FINCN-121
Migrate accounting service from MariaDB to PostgreSQL
  • Loading branch information
Izakey committed Sep 2, 2019
2 parents d8f36aa + 4305780 commit 626a19a6f5fd3ec07463de8fc2515313ac187f69
Showing 22 changed files with 120 additions and 121 deletions.
@@ -1,5 +1,5 @@
Apache Fineract CN Accounting
Copyright [2017-2018] The Apache Software Foundation
Copyright [2017-2019] The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
@@ -56,7 +56,7 @@ public class AbstractAccountingTest extends SuiteTestEnvironment{
public static final String TEST_LOGGER = "test-logger";

@ClassRule
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, mariaDBInitializer);
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, postgreSQLInitializer);

@Rule
public final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
@@ -20,7 +20,7 @@

import org.apache.fineract.cn.test.env.TestEnvironment;
import org.apache.fineract.cn.test.fixture.cassandra.CassandraInitializer;
import org.apache.fineract.cn.test.fixture.mariadb.MariaDBInitializer;
import org.apache.fineract.cn.test.fixture.postgresql.PostgreSQLInitializer;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
import org.junit.rules.RunExternalResourceOnce;
@@ -33,11 +33,11 @@ public class SuiteTestEnvironment {
static final String APP_NAME = "accounting-v1";
static final TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
static final CassandraInitializer cassandraInitializer = new CassandraInitializer();
static final MariaDBInitializer mariaDBInitializer = new MariaDBInitializer();
static final PostgreSQLInitializer postgreSQLInitializer = new PostgreSQLInitializer();

@ClassRule
public static TestRule orderClassRules = RuleChain
.outerRule(new RunExternalResourceOnce(testEnvironment))
.around(new RunExternalResourceOnce(cassandraInitializer))
.around(new RunExternalResourceOnce(mariaDBInitializer));
.around(new RunExternalResourceOnce(postgreSQLInitializer));
}
@@ -56,7 +56,7 @@ dependencies {
[group: 'org.apache.fineract.cn', name: 'lang', version: versions.frameworklang],
[group: 'org.apache.fineract.cn', name: 'async', version: versions.frameworkasync],
[group: 'org.apache.fineract.cn', name: 'cassandra', version: versions.frameworkcassandra],
[group: 'org.apache.fineract.cn', name: 'mariadb', version: versions.frameworkmariadb],
[group: 'org.apache.fineract.cn', name: 'postgresql', version: versions.frameworkpostgresql],
[group: 'org.apache.fineract.cn', name: 'command', version: versions.frameworkcommand],
[group: 'org.hibernate', name: 'hibernate-validator', version: versions.validator]
)
@@ -25,7 +25,7 @@
import org.apache.fineract.cn.customer.api.v1.client.CustomerManager;
import org.apache.fineract.cn.lang.config.EnableServiceException;
import org.apache.fineract.cn.lang.config.EnableTenantContext;
import org.apache.fineract.cn.mariadb.config.EnableMariaDB;
import org.apache.fineract.cn.postgresql.config.EnablePostgreSQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -42,7 +42,7 @@
@EnableDiscoveryClient
@EnableAsync
@EnableTenantContext
@EnableMariaDB
@EnablePostgreSQL
@EnableCassandra
@EnableCommandProcessing
@EnableAnubis
@@ -36,7 +36,7 @@
import org.apache.fineract.cn.command.annotation.CommandHandler;
import org.apache.fineract.cn.command.annotation.CommandLogLevel;
import org.apache.fineract.cn.command.annotation.EventEmitter;
import org.apache.fineract.cn.mariadb.domain.FlywayFactoryBean;
import org.apache.fineract.cn.postgresql.domain.FlywayFactoryBean;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationInfoService;
@@ -19,17 +19,9 @@
package org.apache.fineract.cn.accounting.service.internal.repository;

import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.apache.fineract.cn.mariadb.util.LocalDateTimeConverter;
import javax.persistence.*;

import org.apache.fineract.cn.postgresql.util.LocalDateTimeConverter;

@SuppressWarnings({"unused"})
@Entity
@@ -29,89 +29,90 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.fineract.cn.mariadb.util.LocalDateTimeConverter;

import org.apache.fineract.cn.postgresql.util.LocalDateTimeConverter;

@SuppressWarnings({"unused"})
@Entity
@Table(name = "thoth_account_entries")
public class AccountEntryEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "account_id")
private AccountEntity account;
@Column(name = "a_type")
private String type;
@Column(name = "transaction_date")
@Convert(converter = LocalDateTimeConverter.class)
private LocalDateTime transactionDate;
@Column(name = "message")
private String message;
@Column(name = "amount")
private Double amount;
@Column(name = "balance")
private Double balance;

public AccountEntryEntity() {
super();
}

public Long getId() {
return this.id;
}

public void setId(final Long id) {
this.id = id;
}

public AccountEntity getAccount() {
return this.account;
}

public void setAccount(final AccountEntity account) {
this.account = account;
}

public String getType() {
return this.type;
}

public void setType(final String type) {
this.type = type;
}

public LocalDateTime getTransactionDate() {
return this.transactionDate;
}

public void setTransactionDate(final LocalDateTime transactionDate) {
this.transactionDate = transactionDate;
}

public String getMessage() {
return this.message;
}

public void setMessage(final String message) {
this.message = message;
}

public Double getAmount() {
return this.amount;
}

public void setAmount(final Double amount) {
this.amount = amount;
}

public Double getBalance() {
return this.balance;
}

public void setBalance(final Double balance) {
this.balance = balance;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "account_id")
private AccountEntity account;
@Column(name = "a_type")
private String type;
@Column(name = "transaction_date")
@Convert(converter = LocalDateTimeConverter.class)
private LocalDateTime transactionDate;
@Column(name = "message")
private String message;
@Column(name = "amount")
private Double amount;
@Column(name = "balance")
private Double balance;
public AccountEntryEntity() {
super();
}
public Long getId() {
return this.id;
}
public void setId(final Long id) {
this.id = id;
}
public AccountEntity getAccount() {
return this.account;
}
public void setAccount(final AccountEntity account) {
this.account = account;
}
public String getType() {
return this.type;
}
public void setType(final String type) {
this.type = type;
}
public LocalDateTime getTransactionDate() {
return this.transactionDate;
}
public void setTransactionDate(final LocalDateTime transactionDate) {
this.transactionDate = transactionDate;
}
public String getMessage() {
return this.message;
}
public void setMessage(final String message) {
this.message = message;
}
public Double getAmount() {
return this.amount;
}
public void setAmount(final Double amount) {
this.amount = amount;
}
public Double getBalance() {
return this.balance;
}
public void setBalance(final Double balance) {
this.balance = balance;
}
}
@@ -20,7 +20,7 @@

import java.time.LocalDateTime;
import javax.persistence.Convert;
import org.apache.fineract.cn.mariadb.util.LocalDateTimeConverter;
import org.apache.fineract.cn.postgresql.util.LocalDateTimeConverter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -29,7 +29,7 @@
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.apache.fineract.cn.mariadb.util.LocalDateTimeConverter;
import org.apache.fineract.cn.postgresql.util.LocalDateTimeConverter;

@SuppressWarnings("unused")
@Entity
@@ -30,7 +30,7 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.fineract.cn.mariadb.util.LocalDateTimeConverter;
import org.apache.fineract.cn.postgresql.util.LocalDateTimeConverter;

@SuppressWarnings({"unused"})
@Entity
@@ -23,6 +23,11 @@ spring:
enabled: false
config:
enabled: false
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/playground
username: postgres
password: postgres

eureka:
client:
@@ -42,13 +47,13 @@ cassandra:
write: LOCAL_QUORUM
delete: LOCAL_QUORUM

mariadb:
driverClass: org.mariadb.jdbc.Driver
postgresql:
driverClass: org.postgresql.Driver
database: seshat
host: localhost
port: 3306
user: root
password: mysql
port: 5432
user: postgres
password: postgres

bonecp:
idleMaxAgeInMinutes: 240
@@ -18,7 +18,7 @@
--

CREATE TABLE thoth_ledgers (
id BIGINT NOT NULL AUTO_INCREMENT,
id BIGSERIAL,
a_type VARCHAR(32) NOT NULL,
identifier VARCHAR(32) NOT NULL,
a_name VARCHAR(256) NOT NULL,
@@ -34,7 +34,7 @@ CREATE TABLE thoth_ledgers (
);

CREATE TABLE thoth_accounts (
id BIGINT NOT NULL AUTO_INCREMENT,
id BIGSERIAL,
a_type VARCHAR(32) NOT NULL,
identifier VARCHAR(32) NOT NULL,
a_name VARCHAR(256) NOT NULL,
@@ -55,7 +55,7 @@ CREATE TABLE thoth_accounts (
);

CREATE TABLE thoth_account_entries (
id BIGINT NOT NULL AUTO_INCREMENT,
id BIGSERIAL,
account_id BIGINT NULL,
a_type VARCHAR(32) NOT NULL,
transaction_date TIMESTAMP(3) NOT NULL,
@@ -67,7 +67,7 @@ CREATE TABLE thoth_account_entries (
);

CREATE TABLE thoth_commands (
id BIGINT NOT NULL AUTO_INCREMENT,
id BIGSERIAL NOT NULL,
account_id BIGINT NOT NULL,
a_type VARCHAR(32) NOT NULL,
a_comment VARCHAR(32) NULL,
@@ -76,4 +76,4 @@ CREATE TABLE thoth_commands (
CONSTRAINT thoth_commands_pk PRIMARY KEY (id),
CONSTRAINT thoth_commands_accounts_fk FOREIGN KEY (account_id) REFERENCES thoth_accounts (id)
ON UPDATE RESTRICT
);
);
@@ -17,6 +17,6 @@
-- under the License.
--

ALTER TABLE thoth_ledgers ADD COLUMN show_accounts_in_chart BOOLEAN NOT NULL DEFAULT 1;
ALTER TABLE thoth_ledgers ADD COLUMN show_accounts_in_chart BOOLEAN NOT NULL DEFAULT TRUE;

ALTER TABLE thoth_ledgers ALTER COLUMN show_accounts_in_chart DROP DEFAULT;
@@ -18,7 +18,7 @@
--

CREATE TABLE thoth_tx_types (
id BIGINT NOT NULL AUTO_INCREMENT,
id BIGSERIAL NOT NULL,
identifier VARCHAR(32) NOT NULL,
a_name VARCHAR(256) NOT NULL,
description VARCHAR(2048) NULL,
@@ -17,4 +17,4 @@
-- under the License.
--

ALTER TABLE thoth_accounts MODIFY COLUMN identifier VARCHAR(34) NOT NULL;
ALTER TABLE thoth_accounts ALTER COLUMN identifier TYPE VARCHAR(34), ALTER COLUMN identifier SET NOT NULL;

0 comments on commit 626a19a

Please sign in to comment.