mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
undo changes
This commit is contained in:
parent
c728b13f43
commit
ed85248289
@ -10,8 +10,8 @@ export class Transaction extends BaseEntity {
|
||||
@Column({ name: 'state_group_id', unsigned: true, default: null })
|
||||
stateGroupId: number
|
||||
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
|
||||
@Column({ name: 'tx_hash', type: 'binary', length: 48, default: null })
|
||||
txHash: Buffer
|
||||
|
||||
@ -11,8 +11,8 @@ export class UserTransaction extends BaseEntity {
|
||||
@Column({ name: 'transaction_id' })
|
||||
transactionId: number
|
||||
|
||||
@Column({ name: 'type_id' })
|
||||
typeId: number
|
||||
@Column({ name: 'transaction_type_id' })
|
||||
transactionTypeId: number
|
||||
|
||||
@Column({ name: 'balance', type: 'bigint' })
|
||||
balance: number
|
||||
|
||||
@ -8,8 +8,8 @@ export class Transaction extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
|
||||
@Column({ name: 'tx_hash', type: 'binary', length: 48, default: null })
|
||||
txHash: Buffer
|
||||
|
||||
@ -6,8 +6,8 @@ export class Transaction extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
|
||||
@Column({ name: 'user_id', unsigned: true, nullable: false })
|
||||
userId: number
|
||||
|
||||
@ -11,8 +11,8 @@ export class Transaction extends BaseEntity {
|
||||
@Column({ name: 'transaction_id', unsigned: true, nullable: false })
|
||||
transactionId: number
|
||||
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
|
||||
@Column({ type: 'bigint', nullable: false })
|
||||
amount: BigInt
|
||||
|
||||
@ -140,7 +140,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
CREATE TABLE IF NOT EXISTS \`state_errors\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`state_user_id\` int(10) unsigned NOT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`created\` datetime NOT NULL,
|
||||
\`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
@ -196,7 +196,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
\`state_user_id\` int UNSIGNED NOT NULL,
|
||||
\`transaction_id\` int UNSIGNED NOT NULL,
|
||||
\`type_id\` int UNSIGNED NOT NULL,
|
||||
\`transaction_type_id\` int UNSIGNED NOT NULL,
|
||||
\`balance\` bigint(20) DEFAULT 0,
|
||||
\`balance_date\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`id\`)
|
||||
@ -304,7 +304,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
CREATE TABLE IF NOT EXISTS \`transactions\` (
|
||||
\`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`state_group_id\` int(10) unsigned DEFAULT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`tx_hash\` binary(48) DEFAULT NULL,
|
||||
\`memo\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
\`received\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
@ -292,7 +292,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
CREATE TABLE \`state_errors\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`state_user_id\` int(10) unsigned NOT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`created\` datetime NOT NULL,
|
||||
\`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// Remove transactions with type 9 (start decay block). This should affect exactly 1 row
|
||||
await queryFn(`DELETE FROM transactions WHERE type_id = 9;`)
|
||||
await queryFn(`DELETE FROM transactions WHERE transaction_type_id = 9;`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// Create new `user_id` column (former `state_user_id`), with a temporary default of null
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` ADD COLUMN `user_id` int(10) unsigned DEFAULT NULL AFTER `type_id`;',
|
||||
'ALTER TABLE `transactions` ADD COLUMN `user_id` int(10) unsigned DEFAULT NULL AFTER `transaction_type_id`;',
|
||||
)
|
||||
// Create new `amount` column, with a temporary default of null
|
||||
await queryFn(
|
||||
@ -105,7 +105,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
send_receiver_public_key AS receiver_public_key, send_receiver_user_id AS receiver_user_id,
|
||||
amount, send_sender_final_balance AS sender_final_balance
|
||||
FROM transactions
|
||||
WHERE type_id = 2 );
|
||||
WHERE transaction_type_id = 2 );
|
||||
`)
|
||||
|
||||
await queryFn(`
|
||||
@ -115,7 +115,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
( SELECT id AS transaction_id, user_id AS state_user_id,
|
||||
amount, creation_ident_hash AS ident_hash, creation_date AS target_date
|
||||
FROM transactions
|
||||
WHERE type_id = 1 );
|
||||
WHERE transaction_type_id = 1 );
|
||||
`)
|
||||
|
||||
await queryFn('ALTER TABLE `transactions` DROP COLUMN `send_sender_final_balance`;')
|
||||
|
||||
@ -31,7 +31,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
await queryFn('ALTER TABLE `state_user_transactions` RENAME COLUMN state_user_id TO user_id;')
|
||||
// Create new `amount` column, with a temporary default of null
|
||||
await queryFn(
|
||||
'ALTER TABLE `state_user_transactions` ADD COLUMN `amount` bigint(20) DEFAULT NULL AFTER `type_id`;',
|
||||
'ALTER TABLE `state_user_transactions` ADD COLUMN `amount` bigint(20) DEFAULT NULL AFTER `transaction_type_id`;',
|
||||
)
|
||||
// Create new `send_sender_final_balance`
|
||||
await queryFn(
|
||||
@ -89,7 +89,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.signature = transactions.signature,
|
||||
state_user_transactions.pubkey = transactions.pubkey,
|
||||
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash
|
||||
WHERE state_user_transactions.type_id = 1;
|
||||
WHERE state_user_transactions.transaction_type_id = 1;
|
||||
`)
|
||||
|
||||
// Insert Data from `transactions` for sendCoin sender
|
||||
@ -104,7 +104,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.linked_user_id = transactions.send_receiver_user_id,
|
||||
state_user_transactions.linked_state_user_transaction_id = (
|
||||
SELECT id FROM state_user_transactions AS sut
|
||||
WHERE sut.type_id = 2
|
||||
WHERE sut.transaction_type_id = 2
|
||||
AND sut.transaction_id = state_user_transactions.transaction_id
|
||||
AND sut.user_id = transactions.send_receiver_user_id
|
||||
),
|
||||
@ -112,7 +112,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.signature = transactions.signature,
|
||||
state_user_transactions.pubkey = transactions.pubkey,
|
||||
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash
|
||||
WHERE state_user_transactions.type_id = 2
|
||||
WHERE state_user_transactions.transaction_type_id = 2
|
||||
AND state_user_transactions.user_id = transactions.user_id;
|
||||
`)
|
||||
|
||||
@ -128,7 +128,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.linked_user_id = transactions.user_id,
|
||||
state_user_transactions.linked_state_user_transaction_id = (
|
||||
SELECT id FROM state_user_transactions AS sut
|
||||
WHERE sut.type_id = 2
|
||||
WHERE sut.transaction_type_id = 2
|
||||
AND sut.transaction_id = state_user_transactions.transaction_id
|
||||
AND sut.user_id = transactions.user_id
|
||||
),
|
||||
@ -136,8 +136,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.signature = transactions.signature,
|
||||
state_user_transactions.pubkey = transactions.send_receiver_public_key,
|
||||
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash,
|
||||
state_user_transactions.type_id = 3
|
||||
WHERE state_user_transactions.type_id = 2
|
||||
state_user_transactions.transaction_type_id = 3
|
||||
WHERE state_user_transactions.transaction_type_id = 2
|
||||
AND state_user_transactions.user_id = transactions.send_receiver_user_id;
|
||||
`)
|
||||
|
||||
@ -161,7 +161,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn('RENAME TABLE `transactions` TO `state_user_transactions`;')
|
||||
await queryFn(`CREATE TABLE \`transactions\` (
|
||||
\`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`user_id\` int(10) unsigned NOT NULL,
|
||||
\`amount\` bigint(20) NOT NULL,
|
||||
\`tx_hash\` binary(48) DEFAULT NULL,
|
||||
@ -179,13 +179,13 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO transactions (
|
||||
id, type_id, user_id, amount,
|
||||
id, transaction_type_id, user_id, amount,
|
||||
tx_hash, memo, received, signature, pubkey,
|
||||
creation_ident_hash, creation_date,
|
||||
send_receiver_public_key, send_receiver_user_id,
|
||||
send_sender_final_balance
|
||||
)
|
||||
SELECT transaction_id AS id, type_id,
|
||||
SELECT transaction_id AS id, transaction_type_id,
|
||||
user_id, amount, tx_hash, memo, received,
|
||||
signature, pubkey, creation_ident_hash,
|
||||
creation_date, send_receiver_public_key,
|
||||
@ -194,12 +194,12 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
FROM state_user_transactions LEFT JOIN (
|
||||
SELECT id, pubkey AS send_receiver_public_key
|
||||
FROM state_user_transactions AS sut
|
||||
WHERE sut.type_id = 3
|
||||
WHERE sut.transaction_type_id = 3
|
||||
) AS sutj ON sutj.id = state_user_transactions.id
|
||||
WHERE type_id IN (1,2)
|
||||
WHERE transaction_type_id IN (1,2)
|
||||
`)
|
||||
await queryFn(
|
||||
'UPDATE state_user_transactions SET type_id = 2 WHERE type_id = 3;',
|
||||
'UPDATE state_user_transactions SET transaction_type_id = 2 WHERE transaction_type_id = 3;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `creation_ident_hash`;')
|
||||
await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `pubkey`;')
|
||||
|
||||
@ -23,8 +23,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
// drop column `creation_ident_hash`, it is not needed
|
||||
await queryFn('ALTER TABLE `transactions` DROP COLUMN `creation_ident_hash`;')
|
||||
|
||||
// rename `type_id` to `type_id`
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO type_id;')
|
||||
// rename `transaction_type_id` to `type_id`
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN transaction_type_id TO type_id;')
|
||||
// rename `linked_state_user_transaction_id` to `linked_transaction_id`
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` RENAME COLUMN linked_state_user_transaction_id TO linked_transaction_id;',
|
||||
@ -43,7 +43,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` RENAME COLUMN linked_transaction_id TO linked_state_user_transaction_id;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO type_id;')
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO transaction_type_id;')
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` ADD COLUMN `creation_ident_hash` binary(32) DEFAULT NULL AFTER `linked_state_user_transaction_id`;',
|
||||
)
|
||||
|
||||
@ -40,7 +40,7 @@ interface Decay {
|
||||
duration: number | null
|
||||
}
|
||||
|
||||
export enum TypeId {
|
||||
export enum TransactionTypeId {
|
||||
CREATION = 1,
|
||||
SEND = 2,
|
||||
RECEIVE = 3,
|
||||
@ -162,7 +162,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
|
||||
// This should also fix the rounding error on amount
|
||||
let decAmount = new Decimal(transaction.amount).dividedBy(10000).toDecimalPlaces(2)
|
||||
if (transaction.type_id === TypeId.SEND) {
|
||||
if (transaction.type_id === TransactionTypeId.SEND) {
|
||||
decAmount = decAmount.mul(-1)
|
||||
}
|
||||
const decayStartDate = previous ? previous.balance_date : transaction.balance_date
|
||||
|
||||
@ -61,7 +61,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn(`
|
||||
INSERT INTO \`state_balances\`
|
||||
(state_user_id, modified, record_date, amount)
|
||||
SELECT user_id as state_user_id, balance_date as modified, balance_date as record_date, amount as amount FROM
|
||||
SELECT user_id as state_user_id, balance_date as modified, balance_date as record_date, amount * 10000 as amount FROM
|
||||
(SELECT user_id as uid, MAX(balance_date) AS date FROM transactions GROUP BY uid) AS t
|
||||
LEFT JOIN transactions ON t.uid = transactions.user_id AND t.date = transactions.balance_date;
|
||||
`)
|
||||
@ -96,9 +96,9 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
temp_dec_old_balance = dec_balance,
|
||||
temp_dec_diff_send_sender_final_balance = 0,
|
||||
temp_dec_send_sender_final_balance = dec_balance,
|
||||
balance = dec_balance,
|
||||
send_sender_final_balance = dec_balance,
|
||||
amount = dec_amount;
|
||||
balance = dec_balance * 10000,
|
||||
send_sender_final_balance = dec_balance * 10000,
|
||||
amount = dec_amount * 10000;
|
||||
`)
|
||||
|
||||
await queryFn('ALTER TABLE `transactions` MODIFY COLUMN `amount` bigint(20) NOT NULL;')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user