Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add brc20 stats view #203

Draft
wants to merge 66 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
60687db
chore: add brc20 migrations
rafaelcr May 15, 2023
bf4c7f6
feat: start storing token deploys
rafaelcr May 16, 2023
32e90f7
feat: mints with balance changes
rafaelcr May 17, 2023
7098298
chore: events table draft
rafaelcr May 17, 2023
f9c6654
feat: first balance endpoint
rafaelcr May 17, 2023
61b4139
fix: balances and rollbacks
rafaelcr May 18, 2023
8fad6b9
feat: token info endpoint
rafaelcr May 19, 2023
ae2049b
feat: tokens endpoint as paginated index
rafaelcr May 19, 2023
f09eb5b
test: paginated index
rafaelcr May 19, 2023
b114f6e
test: brc20 format
rafaelcr May 19, 2023
d3f3855
chore: merge develop
rafaelcr May 31, 2023
5c58dde
chore: more standard validation
rafaelcr May 31, 2023
f6fd0a6
fix: tick must be 4 bytes or less
rafaelcr May 31, 2023
0b56c19
chore: conflicts
rafaelcr Jun 12, 2023
aa15b0e
fix: invalid decimal count
rafaelcr Jun 12, 2023
c8e5820
feat: mint within supply
rafaelcr Jun 12, 2023
187d2d7
test: mint limit
rafaelcr Jun 12, 2023
e612dc0
chore: first transfers
rafaelcr Jun 13, 2023
f8780d0
test: dont exceed avail balance for transfer
rafaelcr Jun 13, 2023
edde5d1
test: multiple transfers in block
rafaelcr Jun 13, 2023
dd8ec07
feat: first balance transfers
rafaelcr Jun 13, 2023
542ec34
fix: transfers only usable once
rafaelcr Jun 15, 2023
da5b4b0
refactor: extract to separate functions
rafaelcr Jun 15, 2023
0732048
fix: remove old json content tables
rafaelcr Jun 15, 2023
687c2e4
fix: balances/:address
rafaelcr Jun 16, 2023
5d35d5b
feat: token details
rafaelcr Jun 21, 2023
e466984
Merge branch 'develop' into brc-20
rafaelcr Jun 22, 2023
a01f77e
feat: holders endpoint
rafaelcr Jun 25, 2023
9050499
chore: merge from master
rafaelcr Jun 27, 2023
b352c3b
chore: merge latest develop
rafaelcr Jul 19, 2023
44d9184
refactor: move brc20 pg to separate file
rafaelcr Jul 20, 2023
354ddd0
fix: add indexes for fks
rafaelcr Jul 20, 2023
8cc7f8a
fix: remove old json schemas
rafaelcr Jul 20, 2023
3db302c
refactor: move brc-20 files to its own folder
rafaelcr Jul 20, 2023
e57a8fc
Merge branch 'beta' into brc-20
rafaelcr Jul 24, 2023
026c275
fix: allow gap fills for transfers
rafaelcr Jul 24, 2023
7abc51d
chore: merge beta
rafaelcr Aug 16, 2023
2a4700c
fix: only consider blessed inscriptions
rafaelcr Aug 16, 2023
ced5cb3
feat: brc-20 balance at block (#186)
rafaelcr Aug 16, 2023
6da2ba9
build: release for brc-20 branch
rafaelcr Aug 17, 2023
8c1975c
Merge branch 'brc-20' of github.com:hirosystems/ordinals-api into brc-20
rafaelcr Aug 17, 2023
9047cd3
chore(release): 1.0.0-brc-20.1 [skip ci]
semantic-release-bot Aug 17, 2023
c1939ce
feat: add more brc20 features (#183)
janniks Aug 23, 2023
3807334
fix: optimize inscription and brc-20 inserts (#189)
rafaelcr Aug 23, 2023
66aa721
chore(release): 1.0.0-brc-20.2 [skip ci]
semantic-release-bot Aug 24, 2023
e23012a
fix: sending transfer as fee returns amt to sender
rafaelcr Aug 24, 2023
b428bb4
fix: add unique indexes for mints and transfers
rafaelcr Aug 24, 2023
eb6e7fd
chore(release): 1.0.0-brc-20.3 [skip ci]
semantic-release-bot Aug 24, 2023
0e673a7
fix: upgrade api-toolkit (#190)
rafaelcr Aug 24, 2023
7d6705a
fix: refresh supplies view only if BRC-20 is enabled
rafaelcr Aug 25, 2023
33d70a4
chore(release): 1.0.0-brc-20.4 [skip ci]
semantic-release-bot Aug 25, 2023
9a9c5de
fix: change uniqueness constraint in locations table
rafaelcr Aug 25, 2023
50a7bc3
Merge branch 'brc-20' of github.com:hirosystems/ordinals-api into brc-20
rafaelcr Aug 25, 2023
78c3800
chore(release): 1.0.0-brc-20.5 [skip ci]
semantic-release-bot Aug 25, 2023
bef5f23
fix: place a cap on max insertion size
rafaelcr Aug 26, 2023
04f2666
chore(release): 1.0.0-brc-20.6 [skip ci]
semantic-release-bot Aug 26, 2023
71ce1a5
fix: guard against empty recursion refs
rafaelcr Aug 28, 2023
b1d3f2b
Merge branch 'brc-20' of github.com:hirosystems/ordinals-api into brc-20
rafaelcr Aug 28, 2023
ab2f7bf
fix: optimize inscription backfill indexes (#197)
rafaelcr Aug 28, 2023
63571ee
fix: add recursion backfill and temporary skip (#198)
rafaelcr Aug 28, 2023
8f973a3
fix: dont update cache timestamp during ingestion (#200)
rafaelcr Aug 28, 2023
9c8508b
fix: do not insert repeated recursions (#199)
rafaelcr Aug 28, 2023
98d69f9
chore: lock commit-analyzer to 9.0.2; rm dup plugins in releaserc file
deantchi Aug 28, 2023
a880864
chore: revert releaserc file
deantchi Aug 28, 2023
4ebc106
fix: split recursion insertion into chunks (#201)
rafaelcr Aug 29, 2023
2ade47f
fix: add brc20 stats view
janniks Aug 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
@semantic-release/changelog
@semantic-release/git
conventional-changelog-conventionalcommits
@semantic-release/[email protected]

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
Expand Down
52 changes: 35 additions & 17 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
{
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/github",
"@semantic-release/changelog",
"@semantic-release/git"
]
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
},
{
"name": "brc-20",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/github",
"@semantic-release/changelog",
"@semantic-release/git"
]
}
100 changes: 100 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,103 @@
## [1.0.0-brc-20.6](https://github.com/hirosystems/ordinals-api/compare/v1.0.0-brc-20.5...v1.0.0-brc-20.6) (2023-08-26)


### Bug Fixes

* place a cap on max insertion size ([bef5f23](https://github.com/hirosystems/ordinals-api/commit/bef5f23891b0a041bc27f54e507fead928306c95))

## [1.0.0-brc-20.5](https://github.com/hirosystems/ordinals-api/compare/v1.0.0-brc-20.4...v1.0.0-brc-20.5) (2023-08-25)


### Bug Fixes

* change uniqueness constraint in locations table ([9a9c5de](https://github.com/hirosystems/ordinals-api/commit/9a9c5de7ff76557e2728b726363d68833d05a689))

## [1.0.0-brc-20.4](https://github.com/hirosystems/ordinals-api/compare/v1.0.0-brc-20.3...v1.0.0-brc-20.4) (2023-08-25)


### Bug Fixes

* refresh supplies view only if BRC-20 is enabled ([7d6705a](https://github.com/hirosystems/ordinals-api/commit/7d6705a82f2acec5531b53d2d352f7fa04bf1c51))
* upgrade api-toolkit ([#190](https://github.com/hirosystems/ordinals-api/issues/190)) ([0e673a7](https://github.com/hirosystems/ordinals-api/commit/0e673a7ab327e98b85b3f6289fc7addadee6b1d2))

## [1.0.0-brc-20.3](https://github.com/hirosystems/ordinals-api/compare/v1.0.0-brc-20.2...v1.0.0-brc-20.3) (2023-08-24)


### Bug Fixes

* add unique indexes for mints and transfers ([b428bb4](https://github.com/hirosystems/ordinals-api/commit/b428bb48ef2b2a3eda6f3366fbd7fd488d090d4d))
* sending transfer as fee returns amt to sender ([e23012a](https://github.com/hirosystems/ordinals-api/commit/e23012a926eef80e1d467ef28f618fae989426fd))

## [1.0.0-brc-20.2](https://github.com/hirosystems/ordinals-api/compare/v1.0.0-brc-20.1...v1.0.0-brc-20.2) (2023-08-24)


### Features

* add more brc20 features ([#183](https://github.com/hirosystems/ordinals-api/issues/183)) ([c1939ce](https://github.com/hirosystems/ordinals-api/commit/c1939cee3a40df5f285d3bb749c8b29cea4bb271))


### Bug Fixes

* optimize inscription and brc-20 inserts ([#189](https://github.com/hirosystems/ordinals-api/issues/189)) ([3807334](https://github.com/hirosystems/ordinals-api/commit/38073341163bc1c5cea44b66ad3da505f2ce4273))

## [1.0.0-brc-20.1](https://github.com/hirosystems/ordinals-api/compare/v0.4.15...v1.0.0-brc-20.1) (2023-08-17)


### ⚠ BREAKING CHANGES

* optimize transfer replay capability (#129)

### Features

* add inscription number sort option ([#168](https://github.com/hirosystems/ordinals-api/issues/168)) ([9f4cdbc](https://github.com/hirosystems/ordinals-api/commit/9f4cdbc96f2efa4610e771df74b11951803cb8a6))
* add stats endpoint for inscription counts ([#70](https://github.com/hirosystems/ordinals-api/issues/70)) ([ac18e62](https://github.com/hirosystems/ordinals-api/commit/ac18e621ed7e8ea2fc5a5e536d59a152c3a1f345))
* brc-20 balance at block ([#186](https://github.com/hirosystems/ordinals-api/issues/186)) ([ced5cb3](https://github.com/hirosystems/ordinals-api/commit/ced5cb3306bd0e242503a86f8c94911c2d57161f))
* detect and tag recursive inscriptions ([#167](https://github.com/hirosystems/ordinals-api/issues/167)) ([fb36285](https://github.com/hirosystems/ordinals-api/commit/fb362857c2c3cf4c098f6604b49d77efa6f95d8b))
* first balance endpoint ([f9c6654](https://github.com/hirosystems/ordinals-api/commit/f9c66540b9d173d2981bc2af5ee13fd082dc5547))
* first balance transfers ([dd8ec07](https://github.com/hirosystems/ordinals-api/commit/dd8ec07d366e6bf15e74b528077c8fa1836958e9))
* holders endpoint ([a01f77e](https://github.com/hirosystems/ordinals-api/commit/a01f77ef6c9c03576a07a7cdc14d0279afc44cbb))
* mint within supply ([c8e5820](https://github.com/hirosystems/ordinals-api/commit/c8e582055956c9381d14d5ec1bae5a70c0a4d4a8))
* mints with balance changes ([32e90f7](https://github.com/hirosystems/ordinals-api/commit/32e90f73696aa403417869f0c71fa76da115048e))
* optimize transfer replay capability ([#129](https://github.com/hirosystems/ordinals-api/issues/129)) ([97874cc](https://github.com/hirosystems/ordinals-api/commit/97874cc1461d4e321d5143c70d68927ace62eec5))
* start storing token deploys ([bf4c7f6](https://github.com/hirosystems/ordinals-api/commit/bf4c7f6f27903f18d30ddb7fc2b1a779cc991114))
* token details ([5d35d5b](https://github.com/hirosystems/ordinals-api/commit/5d35d5b0eefb46eeac91ead52f4909279e39404d))
* token info endpoint ([8fad6b9](https://github.com/hirosystems/ordinals-api/commit/8fad6b96c0fffc302a3e61922677bdfb56b74b85))
* tokens endpoint as paginated index ([ae2049b](https://github.com/hirosystems/ordinals-api/commit/ae2049baf04950d810aa997bc0f31b585aaf3391))


### Bug Fixes

* add address column to genesis and current ([d71e1d4](https://github.com/hirosystems/ordinals-api/commit/d71e1d49dece39df1c19c0bb35a43129ef1a31e9))
* add indexes for fks ([354ddd0](https://github.com/hirosystems/ordinals-api/commit/354ddd0559a32a2aba1d407a2c7486348eb91d1c))
* add secondary sorting by inscription number ([#177](https://github.com/hirosystems/ordinals-api/issues/177)) ([99959df](https://github.com/hirosystems/ordinals-api/commit/99959dfe6ec3de9288ce47bd8ef4d72535c19468))
* allow gap fills for transfers ([026c275](https://github.com/hirosystems/ordinals-api/commit/026c2755483efbc8b54753a9a1bf315a6a833d88))
* allow multiple transfers of an inscription in one block ([#132](https://github.com/hirosystems/ordinals-api/issues/132)) ([bc545f0](https://github.com/hirosystems/ordinals-api/commit/bc545f0c1d06ea54ceb5d6ba30a9031d04c7e01e))
* auto predicate registration option ([e1ed7c7](https://github.com/hirosystems/ordinals-api/commit/e1ed7c773dfba99f0b098debb3d865da46d8d10e))
* balances and rollbacks ([61b4139](https://github.com/hirosystems/ordinals-api/commit/61b413955f6ce1428a6a3b1c6b023ae4464c111d))
* balances/:address ([687c2e4](https://github.com/hirosystems/ordinals-api/commit/687c2e43cc5782a2521c3442c0d7fcfe90943b67))
* build beta image ([13f2c13](https://github.com/hirosystems/ordinals-api/commit/13f2c13384a00f9bfd58b7ddd88a49e7abbbe588))
* build event server using chainhook client library ([#105](https://github.com/hirosystems/ordinals-api/issues/105)) ([ab4c795](https://github.com/hirosystems/ordinals-api/commit/ab4c795d1621078950e4defa3330ae597f46d6ac))
* chainhook client upgrades ([9a96492](https://github.com/hirosystems/ordinals-api/commit/9a9649251dd449d6784aa4f6cd448c6f1b6cb687))
* consider `tx_index` in transfers by block endpoint ([#178](https://github.com/hirosystems/ordinals-api/issues/178)) ([ed517d6](https://github.com/hirosystems/ordinals-api/commit/ed517d6eb01b2a780ef0fb89fc5a65582d5e575e))
* introduce materialized view to count address inscriptions ([#147](https://github.com/hirosystems/ordinals-api/issues/147)) ([09a95d5](https://github.com/hirosystems/ordinals-api/commit/09a95d55276be8b52ea19c90d0e7fa8bca73cfc7))
* invalid decimal count ([aa15b0e](https://github.com/hirosystems/ordinals-api/commit/aa15b0e4843435cacfa12856b881566ba0c2f3a3))
* make etag calculation sensitive to inscription location gap fills and upserts ([#156](https://github.com/hirosystems/ordinals-api/issues/156)) ([5648c9e](https://github.com/hirosystems/ordinals-api/commit/5648c9ea72ee09df4a224937a08f662e78d06edd))
* only consider blessed inscriptions ([2a4700c](https://github.com/hirosystems/ordinals-api/commit/2a4700c5ca851b799fba534ff8060004f7ca2f5d))
* optimize COUNT calculations via the use of count tables ([#175](https://github.com/hirosystems/ordinals-api/issues/175)) ([31498bd](https://github.com/hirosystems/ordinals-api/commit/31498bdb57203bd6c28eccac4446a9d169a3fe18))
* refresh views in parallel ([#154](https://github.com/hirosystems/ordinals-api/issues/154)) ([a7674a9](https://github.com/hirosystems/ordinals-api/commit/a7674a92efcb580b67c3510a2bf09ffb752e2ef0))
* remove old json content tables ([0732048](https://github.com/hirosystems/ordinals-api/commit/07320489889b85c881ab49a4ce10d0d21a750114))
* remove old json schemas ([8cc7f8a](https://github.com/hirosystems/ordinals-api/commit/8cc7f8adcb9d70cd511b09583dd45f9dc770cd92))
* remove unused json functions ([#165](https://github.com/hirosystems/ordinals-api/issues/165)) ([3eb0e24](https://github.com/hirosystems/ordinals-api/commit/3eb0e248a98913b8e4c56949e8ebd174a3f1faae))
* rename location pointer tables ([b84d27e](https://github.com/hirosystems/ordinals-api/commit/b84d27e3624737e59c949906cafa8d76a329c0a0))
* rollback location pointers ([#174](https://github.com/hirosystems/ordinals-api/issues/174)) ([3c9d7f0](https://github.com/hirosystems/ordinals-api/commit/3c9d7f07d14aed2bad1c07d69f7170d74a85d575))
* save tx_index on locations to support transfers on same block ([#145](https://github.com/hirosystems/ordinals-api/issues/145)) ([30a9635](https://github.com/hirosystems/ordinals-api/commit/30a96358c2b7c4c40f908e116478e3ddd83d8857))
* skip db migrations during readonly mode ([d5157f0](https://github.com/hirosystems/ordinals-api/commit/d5157f02646ceb6c58b73575d8ff4afc8833b97e))
* tick must be 4 bytes or less ([f6fd0a6](https://github.com/hirosystems/ordinals-api/commit/f6fd0a656d6520f90eda4d6610c04a077fa70354))
* transfers only usable once ([542ec34](https://github.com/hirosystems/ordinals-api/commit/542ec34292d7535d01f62832b270e11b80b59da4))
* upgrade chainhook client ([cbbb951](https://github.com/hirosystems/ordinals-api/commit/cbbb9512734f83c27da91b57fd5825b22c510c33))
* upgrade chainhook client to 1.3.3 ([ee66f93](https://github.com/hirosystems/ordinals-api/commit/ee66f93a1d06c786c2eb7ce415df28c7fa8d0032))
* warn correctly on missing prev locations ([879bf55](https://github.com/hirosystems/ordinals-api/commit/879bf55b0fc7efd830c5cc0e1d742818177e8344))

## [1.0.0-beta.15](https://github.com/hirosystems/ordinals-api/compare/v1.0.0-beta.14...v1.0.0-beta.15) (2023-08-04)


Expand Down
53 changes: 53 additions & 0 deletions migrations/1684174644336_brc20-deploys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';

export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('brc20_deploys', {
id: {
type: 'bigserial',
primaryKey: true,
},
inscription_id: {
type: 'bigint',
notNull: true,
},
block_height: {
type: 'bigint',
notNull: true,
},
tx_id: {
type: 'text',
notNull: true,
},
address: {
type: 'text',
notNull: true,
},
ticker: {
type: 'text',
notNull: true,
},
max: {
type: 'numeric',
notNull: true,
},
limit: {
type: 'numeric',
},
decimals: {
type: 'int',
notNull: true,
},
});
pgm.createConstraint(
'brc20_deploys',
'brc20_deploys_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createIndex('brc20_deploys', ['inscription_id']);
pgm.createIndex('brc20_deploys', 'LOWER(ticker)', { unique: true });
pgm.createIndex('brc20_deploys', ['block_height']);
pgm.createIndex('brc20_deploys', ['address']);
}
51 changes: 51 additions & 0 deletions migrations/1684175792528_brc20-mints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';

export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('brc20_mints', {
id: {
type: 'bigserial',
primaryKey: true,
},
inscription_id: {
type: 'bigint',
notNull: true,
},
brc20_deploy_id: {
type: 'bigint',
notNull: true,
},
block_height: {
type: 'bigint',
notNull: true,
},
tx_id: {
type: 'text',
notNull: true,
},
address: {
type: 'text',
notNull: true,
},
amount: {
type: 'numeric',
notNull: true,
},
});
pgm.createConstraint(
'brc20_mints',
'brc20_mints_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'brc20_mints',
'brc20_mints_brc20_deploy_id_fk',
'FOREIGN KEY(brc20_deploy_id) REFERENCES brc20_deploys(id) ON DELETE CASCADE'
);
pgm.createIndex('brc20_mints', ['inscription_id']);
pgm.createIndex('brc20_mints', ['brc20_deploy_id']);
pgm.createIndex('brc20_mints', ['block_height']);
pgm.createIndex('brc20_mints', ['address']);
}
55 changes: 55 additions & 0 deletions migrations/1684175795592_brc20-transfers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';

export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('brc20_transfers', {
id: {
type: 'bigserial',
primaryKey: true,
},
inscription_id: {
type: 'bigint',
notNull: true,
},
brc20_deploy_id: {
type: 'bigint',
notNull: true,
},
block_height: {
type: 'bigint',
notNull: true,
},
tx_id: {
type: 'text',
notNull: true,
},
from_address: {
type: 'text',
notNull: true,
},
to_address: {
type: 'text',
},
amount: {
type: 'numeric',
notNull: true,
},
});
pgm.createConstraint(
'brc20_transfers',
'brc20_transfers_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'brc20_transfers',
'brc20_transfers_brc20_deploy_id_fk',
'FOREIGN KEY(brc20_deploy_id) REFERENCES brc20_deploys(id) ON DELETE CASCADE'
);
pgm.createIndex('brc20_transfers', ['inscription_id']);
pgm.createIndex('brc20_transfers', ['brc20_deploy_id']);
pgm.createIndex('brc20_transfers', ['block_height']);
pgm.createIndex('brc20_transfers', ['from_address']);
pgm.createIndex('brc20_transfers', ['to_address']);
}
63 changes: 63 additions & 0 deletions migrations/1684175810998_brc20-balances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';

export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('brc20_balances', {
id: {
type: 'bigserial',
primaryKey: true,
},
inscription_id: {
type: 'bigint',
notNull: true,
},
location_id: {
type: 'bigint',
notNull: true,
},
brc20_deploy_id: {
type: 'bigint',
notNull: true,
},
address: {
type: 'text',
},
avail_balance: {
type: 'numeric',
notNull: true,
},
trans_balance: {
type: 'numeric',
notNull: true,
},
type: {
type: 'smallint',
notNull: true,
},
});
pgm.createConstraint(
'brc20_balances',
'brc20_balances_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'brc20_balances',
'brc20_balances_location_id_fk',
'FOREIGN KEY(location_id) REFERENCES locations(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'brc20_balances',
'brc20_balances_brc20_deploy_id_fk',
'FOREIGN KEY(brc20_deploy_id) REFERENCES brc20_deploys(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'brc20_balances',
'brc20_balances_inscription_id_type_unique',
'UNIQUE(inscription_id, type)'
);
pgm.createIndex('brc20_balances', ['location_id']);
pgm.createIndex('brc20_balances', ['brc20_deploy_id']);
pgm.createIndex('brc20_balances', ['address']);
}
Loading
Loading