From a0b61eeeb7000a79b8f4a8f70ef95d0a1b8659d5 Mon Sep 17 00:00:00 2001 From: filipdjokic Date: Wed, 21 Jan 2026 09:27:17 +0100 Subject: [PATCH] fix: Change fee amount column type to numeric --- .../migrations/0004_sloppy_paladin.sql | 4 + .../migrations/meta/0004_snapshot.json | 856 ++++++++++++++++++ src/database/migrations/meta/_journal.json | 73 +- src/database/schema.ts | 9 +- 4 files changed, 905 insertions(+), 37 deletions(-) create mode 100644 src/database/migrations/0004_sloppy_paladin.sql create mode 100644 src/database/migrations/meta/0004_snapshot.json diff --git a/src/database/migrations/0004_sloppy_paladin.sql b/src/database/migrations/0004_sloppy_paladin.sql new file mode 100644 index 00000000..da50f4d9 --- /dev/null +++ b/src/database/migrations/0004_sloppy_paladin.sql @@ -0,0 +1,4 @@ +ALTER TABLE "did_mainnet" ALTER COLUMN "amount" SET DATA TYPE numeric;--> statement-breakpoint +ALTER TABLE "did_testnet" ALTER COLUMN "amount" SET DATA TYPE numeric;--> statement-breakpoint +ALTER TABLE "resource_mainnet" ALTER COLUMN "amount" SET DATA TYPE numeric;--> statement-breakpoint +ALTER TABLE "resource_testnet" ALTER COLUMN "amount" SET DATA TYPE numeric; \ No newline at end of file diff --git a/src/database/migrations/meta/0004_snapshot.json b/src/database/migrations/meta/0004_snapshot.json new file mode 100644 index 00000000..2df34070 --- /dev/null +++ b/src/database/migrations/meta/0004_snapshot.json @@ -0,0 +1,856 @@ +{ + "id": "29e2517a-42dd-435c-98ea-637d9db432c4", + "prevId": "44c374c8-9d41-4141-a79f-f0743a3d863b", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.denom_mainnet": { + "name": "denom_mainnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ledger_denom": { + "name": "ledger_denom", + "type": "denoms_enum_mainnet", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'ncheq'" + }, + "friendly_denom": { + "name": "friendly_denom", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'CHEQ'" + }, + "exponent": { + "name": "exponent", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "denom_mainnet_ledger_denom_unique": { + "name": "denom_mainnet_ledger_denom_unique", + "nullsNotDistinct": false, + "columns": [ + "ledger_denom" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.denom_testnet": { + "name": "denom_testnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ledger_denom": { + "name": "ledger_denom", + "type": "denoms_enum_testnet", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'ncheq'" + }, + "friendly_denom": { + "name": "friendly_denom", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'ncheq'" + }, + "exponent": { + "name": "exponent", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "denom_testnet_ledger_denom_unique": { + "name": "denom_testnet_ledger_denom_unique", + "nullsNotDistinct": false, + "columns": [ + "ledger_denom" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.did_mainnet": { + "name": "did_mainnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "did_id": { + "name": "did_id", + "type": "varchar(54)", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "fee_payer": { + "name": "fee_payer", + "type": "varchar(44)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "denom": { + "name": "denom", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "block_height": { + "name": "block_height", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transaction_hash": { + "name": "transaction_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_did_mainnet_tx_op_did": { + "name": "idx_did_mainnet_tx_op_did", + "columns": [ + { + "expression": "transaction_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "did_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "did_mainnet_operation_type_operation_types_mainnet_id_fk": { + "name": "did_mainnet_operation_type_operation_types_mainnet_id_fk", + "tableFrom": "did_mainnet", + "tableTo": "operation_types_mainnet", + "columnsFrom": [ + "operation_type" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "did_mainnet_denom_denom_mainnet_id_fk": { + "name": "did_mainnet_denom_denom_mainnet_id_fk", + "tableFrom": "did_mainnet", + "tableTo": "denom_mainnet", + "columnsFrom": [ + "denom" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.did_testnet": { + "name": "did_testnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "did_id": { + "name": "did_id", + "type": "varchar(54)", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "fee_payer": { + "name": "fee_payer", + "type": "varchar(44)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "denom": { + "name": "denom", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "block_height": { + "name": "block_height", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transaction_hash": { + "name": "transaction_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_did_testnet_tx_op_did": { + "name": "idx_did_testnet_tx_op_did", + "columns": [ + { + "expression": "transaction_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "did_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "did_testnet_operation_type_operation_types_testnet_id_fk": { + "name": "did_testnet_operation_type_operation_types_testnet_id_fk", + "tableFrom": "did_testnet", + "tableTo": "operation_types_testnet", + "columnsFrom": [ + "operation_type" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "did_testnet_denom_denom_testnet_id_fk": { + "name": "did_testnet_denom_denom_testnet_id_fk", + "tableFrom": "did_testnet", + "tableTo": "denom_testnet", + "columnsFrom": [ + "denom" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.operation_types_mainnet": { + "name": "operation_types_mainnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ledger_operation_type": { + "name": "ledger_operation_type", + "type": "operation_type_enum_mainnet", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "friendly_operation_type": { + "name": "friendly_operation_type", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'friendly'" + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "operation_types_mainnet_ledger_operation_type_unique": { + "name": "operation_types_mainnet_ledger_operation_type_unique", + "nullsNotDistinct": false, + "columns": [ + "ledger_operation_type" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.operation_types_testnet": { + "name": "operation_types_testnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "ledger_operation_type": { + "name": "ledger_operation_type", + "type": "operation_type_enum_testnet", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "friendly_operation_type": { + "name": "friendly_operation_type", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'friendly'" + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "operation_types_testnet_ledger_operation_type_unique": { + "name": "operation_types_testnet_ledger_operation_type_unique", + "nullsNotDistinct": false, + "columns": [ + "ledger_operation_type" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.resource_mainnet": { + "name": "resource_mainnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "resource_name": { + "name": "resource_name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "did_id": { + "name": "did_id", + "type": "varchar(54)", + "primaryKey": false, + "notNull": false + }, + "fee_payer": { + "name": "fee_payer", + "type": "varchar(44)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "denom": { + "name": "denom", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "block_height": { + "name": "block_height", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transaction_hash": { + "name": "transaction_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_resource_mainnet_tx_op_resource": { + "name": "idx_resource_mainnet_tx_op_resource", + "columns": [ + { + "expression": "transaction_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "resource_mainnet_operation_type_operation_types_mainnet_id_fk": { + "name": "resource_mainnet_operation_type_operation_types_mainnet_id_fk", + "tableFrom": "resource_mainnet", + "tableTo": "operation_types_mainnet", + "columnsFrom": [ + "operation_type" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "resource_mainnet_denom_denom_mainnet_id_fk": { + "name": "resource_mainnet_denom_denom_mainnet_id_fk", + "tableFrom": "resource_mainnet", + "tableTo": "denom_mainnet", + "columnsFrom": [ + "denom" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.resource_testnet": { + "name": "resource_testnet", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "resource_name": { + "name": "resource_name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "did_id": { + "name": "did_id", + "type": "varchar(54)", + "primaryKey": false, + "notNull": false + }, + "fee_payer": { + "name": "fee_payer", + "type": "varchar(44)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "denom": { + "name": "denom", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "block_height": { + "name": "block_height", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transaction_hash": { + "name": "transaction_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_resource_testnet_tx_op_resource": { + "name": "idx_resource_testnet_tx_op_resource", + "columns": [ + { + "expression": "transaction_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "resource_testnet_operation_type_operation_types_testnet_id_fk": { + "name": "resource_testnet_operation_type_operation_types_testnet_id_fk", + "tableFrom": "resource_testnet", + "tableTo": "operation_types_testnet", + "columnsFrom": [ + "operation_type" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "resource_testnet_denom_denom_testnet_id_fk": { + "name": "resource_testnet_denom_denom_testnet_id_fk", + "tableFrom": "resource_testnet", + "tableTo": "denom_testnet", + "columnsFrom": [ + "denom" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.denoms_enum_mainnet": { + "name": "denoms_enum_mainnet", + "schema": "public", + "values": [ + "ncheq" + ] + }, + "public.denoms_enum_testnet": { + "name": "denoms_enum_testnet", + "schema": "public", + "values": [ + "ncheq" + ] + }, + "public.operation_type_enum_mainnet": { + "name": "operation_type_enum_mainnet", + "schema": "public", + "values": [ + "cheqd.did.v2.MsgCreateDidDoc", + "cheqd.did.v2.MsgUpdateDidDoc", + "cheqd.did.v2.MsgDeactivateDidDoc", + "cheqd.resource.v2.MsgCreateResource" + ] + }, + "public.operation_type_enum_testnet": { + "name": "operation_type_enum_testnet", + "schema": "public", + "values": [ + "cheqd.did.v2.MsgCreateDidDoc", + "cheqd.did.v2.MsgUpdateDidDoc", + "cheqd.did.v2.MsgDeactivateDidDoc", + "cheqd.resource.v2.MsgCreateResource" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/database/migrations/meta/_journal.json b/src/database/migrations/meta/_journal.json index 80eaa1a9..c18b2dde 100644 --- a/src/database/migrations/meta/_journal.json +++ b/src/database/migrations/meta/_journal.json @@ -1,34 +1,41 @@ { - "version": "7", - "dialect": "postgresql", - "entries": [ - { - "idx": 0, - "version": "7", - "when": 1741197616979, - "tag": "0000_salty_machine_man", - "breakpoints": true - }, - { - "idx": 1, - "version": "7", - "when": 1741392062249, - "tag": "0001_hard_jane_foster", - "breakpoints": true - }, - { - "idx": 2, - "version": "7", - "when": 1741705797047, - "tag": "0002_dazzling_colossus", - "breakpoints": true - }, - { - "idx": 3, - "version": "7", - "when": 1741774436871, - "tag": "0003_overjoyed_elektra", - "breakpoints": true - } - ] -} + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1741197616979, + "tag": "0000_salty_machine_man", + "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1741392062249, + "tag": "0001_hard_jane_foster", + "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1741705797047, + "tag": "0002_dazzling_colossus", + "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1741774436871, + "tag": "0003_overjoyed_elektra", + "breakpoints": true + }, + { + "idx": 4, + "version": "7", + "when": 1768983905645, + "tag": "0004_sloppy_paladin", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/database/schema.ts b/src/database/schema.ts index 94344ce4..cfe50c4d 100644 --- a/src/database/schema.ts +++ b/src/database/schema.ts @@ -2,6 +2,7 @@ import { pgTable, timestamp, bigint, + numeric, varchar, serial, boolean, @@ -42,7 +43,7 @@ export const didMainnet = pgTable( .notNull() .references(() => operationTypesMainnet.id, { onDelete: 'no action', onUpdate: 'no action' }), feePayer: varchar('fee_payer', { length: 44 }).notNull(), - amount: bigint('amount', { mode: 'bigint' }).notNull(), + amount: numeric('amount', { mode: 'number' }).notNull(), denom: bigint('denom', { mode: 'bigint' }) .notNull() .references(() => denomMainnet.id, { onDelete: 'no action', onUpdate: 'no action' }), @@ -66,7 +67,7 @@ export const resourceMainnet = pgTable( .references(() => operationTypesMainnet.id, { onDelete: 'no action', onUpdate: 'no action' }), didId: varchar('did_id', { length: 54 }), feePayer: varchar('fee_payer', { length: 44 }).notNull(), - amount: bigint('amount', { mode: 'bigint' }).notNull(), + amount: numeric('amount', { mode: 'number' }).notNull(), denom: bigint('denom', { mode: 'bigint' }) .notNull() .references(() => denomMainnet.id, { onDelete: 'no action', onUpdate: 'no action' }), @@ -110,7 +111,7 @@ export const didTestnet = pgTable( .notNull() .references(() => operationTypesTestnet.id, { onDelete: 'no action', onUpdate: 'no action' }), feePayer: varchar('fee_payer', { length: 44 }).notNull(), - amount: bigint('amount', { mode: 'bigint' }).notNull(), + amount: numeric('amount', { mode: 'number' }).notNull(), denom: bigint('denom', { mode: 'bigint' }) .notNull() .references(() => denomTestnet.id, { onDelete: 'no action', onUpdate: 'no action' }), @@ -134,7 +135,7 @@ export const resourceTestnet = pgTable( .references(() => operationTypesTestnet.id, { onDelete: 'no action', onUpdate: 'no action' }), didId: varchar('did_id', { length: 54 }), feePayer: varchar('fee_payer', { length: 44 }).notNull(), - amount: bigint('amount', { mode: 'bigint' }).notNull(), + amount: numeric('amount', { mode: 'number' }).notNull(), denom: bigint('denom', { mode: 'bigint' }) .notNull() .references(() => denomTestnet.id, { onDelete: 'no action', onUpdate: 'no action' }),