-
Notifications
You must be signed in to change notification settings - Fork 108
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
NFT Database Schema #2070
NFT Database Schema #2070
Changes from all commits
b4629e7
2b02169
b3fcc40
c430bbc
ef60be5
2bdebc0
e1100b4
53c56fb
1b1e55f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
------------------- | ||
-- Update and add tables for NFT support | ||
------------------- | ||
|
||
-- Create the enums for the new token columns | ||
CREATE TYPE token_supply_type AS ENUM ('INFINITE', 'FINITE'); | ||
CREATE TYPE token_type AS ENUM ('FUNGIBLE_COMMON', 'NON_FUNGIBLE_UNIQUE'); | ||
|
||
|
||
-- Update the token table | ||
alter table token | ||
add column max_supply bigint not null default 9223372036854775807, -- max long | ||
add column supply_type token_supply_type not null default 'INFINITE', | ||
add column type token_type not null default 'FUNGIBLE_COMMON'; | ||
|
||
-- Create nft table | ||
create table if not exists nft | ||
( | ||
account_id bigint not null, | ||
created_timestamp bigint primary key not null, | ||
deleted boolean default false not null, | ||
modified_timestamp bigint not null, | ||
metadata bytea default '' not null, | ||
serial_number bigint not null, | ||
token_id bigint not null | ||
); | ||
create unique index if not exists nft__token_id_serial_num | ||
on nft (token_id desc, serial_number desc); | ||
comment on table nft is 'Non-Fungible Tokens (NFTs) minted on network'; | ||
|
||
-- Create nft_transfer table | ||
create table if not exists nft_transfer | ||
( | ||
consensus_timestamp bigint not null, | ||
receiver_account_id bigint not null, | ||
sender_account_id bigint not null, | ||
serial_number bigint not null, | ||
token_id bigint not null | ||
); | ||
create unique index if not exists nft_transfer__timestamp_token_id_serial_num | ||
on nft_transfer (consensus_timestamp desc, token_id desc, serial_number desc); | ||
comment on table nft_transfer is 'Crypto account nft transfers'; | ||
|
||
-- Insert new response codes | ||
insert into t_transaction_results (result, proto_id) | ||
values ('ACCOUNT_EXPIRED_AND_PENDING_REMOVAL', 223), | ||
('INVALID_TOKEN_MAX_SUPPLY', 224), | ||
('INVALID_TOKEN_NFT_SERIAL_NUMBER', 225), | ||
('INVALID_NFT_ID', 226); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
-- Supports mirror nodes migrated from v1.0 | ||
------------------- | ||
|
||
-- Create enums for tables | ||
CREATE TYPE token_supply_type AS ENUM ('INFINITE', 'FINITE'); | ||
CREATE TYPE token_type AS ENUM ('FUNGIBLE_COMMON', 'NON_FUNGIBLE_UNIQUE'); | ||
|
||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any opinions on creating all enums at the top vs. creating them in their corresponding table sections? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create at top in one group as you're doing so that the data types exist prior to table definitions. |
||
-- account_balance | ||
create table if not exists account_balance | ||
( | ||
|
@@ -137,6 +141,30 @@ create table if not exists live_hash | |
consensus_timestamp bigint not null | ||
); | ||
|
||
-- nft | ||
create table if not exists nft | ||
( | ||
account_id bigint not null, | ||
created_timestamp bigint primary key not null, | ||
deleted boolean default false not null, | ||
modified_timestamp bigint not null, | ||
metadata bytea default '' not null, | ||
serial_number bigint not null, | ||
token_id bigint not null | ||
); | ||
comment on table nft is 'Non-Fungible Tokens (NFTs) minted on network'; | ||
|
||
-- nft_transfer | ||
create table if not exists nft_transfer | ||
( | ||
consensus_timestamp bigint not null, | ||
receiver_account_id bigint not null, | ||
sender_account_id bigint not null, | ||
serial_number bigint not null, | ||
token_id bigint not null | ||
); | ||
comment on table nft_transfer is 'Crypto account nft transfers'; | ||
|
||
-- non_fee_transfer | ||
create table if not exists non_fee_transfer | ||
( | ||
|
@@ -228,13 +256,16 @@ create table if not exists token | |
initial_supply bigint not null, | ||
kyc_key bytea, | ||
kyc_key_ed25519_hex varchar null, | ||
max_supply bigint not null default 9223372036854775807, -- max long | ||
modified_timestamp bigint not null, | ||
name character varying(100) not null, | ||
supply_key bytea, | ||
supply_key_ed25519_hex varchar null, | ||
supply_type token_supply_type not null default 'INFINITE', | ||
symbol character varying(100) not null, | ||
total_supply bigint not null default 0, | ||
treasury_account_id bigint not null, | ||
type token_type not null default 'FUNGIBLE_COMMON', | ||
wipe_key bytea, | ||
wipe_key_ed25519_hex varchar null | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one isn't part of the NFT protobufs change, but I noticed we were missing it.