lbry-sdk/lbry/db/tables.py

196 lines
6.3 KiB
Python
Raw Normal View History

2020-04-12 02:01:10 +02:00
# pylint: skip-file
2020-04-11 23:27:41 +02:00
from sqlalchemy import (
MetaData, Table, Column, ForeignKey,
2020-04-12 17:59:00 +02:00
LargeBinary, Text, SmallInteger, Integer, BigInteger, Boolean
2020-04-11 23:27:41 +02:00
)
2020-05-01 15:29:44 +02:00
SCHEMA_VERSION = '1.4'
2020-04-11 23:27:41 +02:00
metadata = MetaData()
Version = Table(
'version', metadata,
2020-04-12 17:06:05 +02:00
Column('version', Text, primary_key=True),
2020-04-11 23:27:41 +02:00
)
PubkeyAddress = Table(
'pubkey_address', metadata,
2020-04-12 17:06:05 +02:00
Column('address', Text, primary_key=True),
Column('used_times', Integer, server_default='0'),
2020-04-11 23:27:41 +02:00
)
AccountAddress = Table(
'account_address', metadata,
2020-04-12 17:06:05 +02:00
Column('account', Text, primary_key=True),
Column('address', Text, ForeignKey(PubkeyAddress.columns.address), primary_key=True),
2020-05-02 05:25:07 +02:00
Column('chain', SmallInteger),
2020-04-12 17:06:05 +02:00
Column('pubkey', LargeBinary),
Column('chain_code', LargeBinary),
Column('n', Integer),
2020-05-02 05:25:07 +02:00
Column('depth', SmallInteger),
2020-04-11 23:27:41 +02:00
)
Block = Table(
'block', metadata,
2020-04-12 17:06:05 +02:00
Column('block_hash', LargeBinary, primary_key=True),
Column('previous_hash', LargeBinary),
Column('file_number', SmallInteger),
Column('height', Integer),
2020-06-19 20:28:34 +02:00
Column('timestamp', Integer),
2020-05-01 15:29:44 +02:00
Column('block_filter', LargeBinary, nullable=True)
2020-04-11 23:27:41 +02:00
)
TX = Table(
'tx', metadata,
2020-04-12 17:06:05 +02:00
Column('block_hash', LargeBinary, nullable=True),
Column('tx_hash', LargeBinary, primary_key=True),
Column('raw', LargeBinary),
Column('height', Integer),
Column('position', SmallInteger),
2020-06-19 20:28:34 +02:00
Column('timestamp', Integer, nullable=True),
Column('day', Integer, nullable=True),
2020-04-12 17:06:05 +02:00
Column('is_verified', Boolean, server_default='FALSE'),
Column('purchased_claim_hash', LargeBinary, nullable=True),
2020-05-01 15:29:44 +02:00
Column('tx_filter', LargeBinary, nullable=True)
2020-04-11 23:27:41 +02:00
)
TXO = Table(
'txo', metadata,
2020-04-12 17:06:05 +02:00
Column('tx_hash', LargeBinary, ForeignKey(TX.columns.tx_hash)),
Column('txo_hash', LargeBinary, primary_key=True),
Column('address', Text),
2020-05-02 05:25:07 +02:00
Column('position', SmallInteger),
2020-04-12 17:59:00 +02:00
Column('amount', BigInteger),
2020-05-02 05:25:07 +02:00
Column('script_offset', Integer),
Column('script_length', Integer),
2020-06-05 06:35:22 +02:00
Column('is_spent', Boolean, server_default='0'),
2020-04-12 17:06:05 +02:00
Column('is_reserved', Boolean, server_default='0'),
2020-05-02 05:25:07 +02:00
Column('txo_type', SmallInteger, server_default='0'),
2020-04-12 17:06:05 +02:00
Column('claim_id', Text, nullable=True),
Column('claim_hash', LargeBinary, nullable=True),
Column('claim_name', Text, nullable=True),
2020-04-11 23:27:41 +02:00
)
2020-04-12 17:06:05 +02:00
txo_join_account = TXO.join(AccountAddress, TXO.columns.address == AccountAddress.columns.address)
2020-04-11 23:27:41 +02:00
TXI = Table(
'txi', metadata,
2020-04-12 17:06:05 +02:00
Column('tx_hash', LargeBinary, ForeignKey(TX.columns.tx_hash)),
Column('txo_hash', LargeBinary, ForeignKey(TXO.columns.txo_hash), primary_key=True),
2020-05-01 15:29:44 +02:00
Column('address', Text, nullable=True),
2020-05-02 05:25:07 +02:00
Column('position', SmallInteger),
2020-04-11 23:27:41 +02:00
)
2020-04-12 17:06:05 +02:00
txi_join_account = TXI.join(AccountAddress, TXI.columns.address == AccountAddress.columns.address)
2020-05-01 15:29:44 +02:00
Claim = Table(
'claim', metadata,
Column('claim_hash', LargeBinary, primary_key=True),
2020-05-02 05:25:07 +02:00
Column('claim_id', Text),
2020-05-01 15:29:44 +02:00
Column('claim_name', Text),
2020-05-02 05:25:07 +02:00
Column('normalized', Text),
Column('address', Text),
2020-05-01 15:29:44 +02:00
Column('txo_hash', LargeBinary, ForeignKey(TXO.columns.txo_hash)),
2020-05-02 05:25:07 +02:00
Column('tx_position', SmallInteger),
2020-05-01 15:29:44 +02:00
Column('amount', BigInteger),
2020-05-02 05:25:07 +02:00
Column('timestamp', Integer), # last updated timestamp
Column('creation_timestamp', Integer),
Column('height', Integer), # last updated height
Column('creation_height', Integer),
Column('activation_height', Integer, nullable=True),
2020-06-19 20:28:34 +02:00
Column('expiration_height', Integer, nullable=True),
Column('takeover_height', Integer, nullable=True),
Column('is_controlling', Boolean, server_default='0'),
2020-05-02 05:25:07 +02:00
Column('release_time', Integer, nullable=True),
# normalized#shortest-unique-claim_id
2020-06-19 20:28:34 +02:00
Column('short_url', Text, nullable=True),
2020-05-02 05:25:07 +02:00
# channel's-short_url/normalized#shortest-unique-claim_id-within-channel
Column('canonical_url', Text, nullable=True),
Column('title', Text, nullable=True),
Column('author', Text, nullable=True),
Column('description', Text, nullable=True),
Column('claim_type', SmallInteger),
2020-06-19 20:28:34 +02:00
Column('claim_reposted_count', Integer, server_default='0'),
Column('supports_in_claim_count', Integer, server_default='0'),
2020-05-02 05:25:07 +02:00
# streams
Column('stream_type', Text, nullable=True),
Column('media_type', Text, nullable=True),
Column('fee_amount', BigInteger, server_default='0'),
Column('fee_currency', Text, nullable=True),
Column('duration', Integer, nullable=True),
# reposts
Column('reposted_claim_hash', LargeBinary, nullable=True),
# claims which are channels
2020-06-19 20:28:34 +02:00
Column('public_key', LargeBinary, nullable=True),
2020-05-02 05:25:07 +02:00
Column('public_key_hash', LargeBinary, nullable=True),
2020-06-19 20:28:34 +02:00
Column('public_key_height', Integer, server_default='0'), # height at which public key was last changed
Column('claims_in_channel_count', Integer, server_default='0'),
2020-05-02 05:25:07 +02:00
# claims which are inside channels
2020-05-01 15:29:44 +02:00
Column('channel_hash', LargeBinary, nullable=True),
2020-05-02 05:25:07 +02:00
Column('signature', LargeBinary, nullable=True),
Column('signature_digest', LargeBinary, nullable=True),
2020-06-19 20:28:34 +02:00
Column('is_signature_valid', Boolean, server_default='0'),
2020-05-02 05:25:07 +02:00
Column('support_amount', BigInteger, server_default='0'),
Column('trending_group', BigInteger, server_default='0'),
Column('trending_mixed', BigInteger, server_default='0'),
Column('trending_local', BigInteger, server_default='0'),
Column('trending_global', BigInteger, server_default='0'),
2020-05-01 15:29:44 +02:00
)
Tag = Table(
'tag', metadata,
Column('claim_hash', LargeBinary),
Column('tag', Text),
)
2020-06-05 06:35:22 +02:00
Support = Table(
'support', metadata,
2020-06-19 20:28:34 +02:00
Column('txo_hash', LargeBinary, ForeignKey(TXO.columns.txo_hash), primary_key=True),
Column('claim_hash', LargeBinary, ForeignKey(TXO.columns.claim_hash)),
Column('address', Text),
Column('tx_position', SmallInteger),
Column('activation_height', Integer, nullable=True),
Column('expiration_height', Integer, nullable=True),
Column('amount', BigInteger),
Column('height', Integer),
# support metadata
Column('emoji', Text),
# signed supports
Column('channel_hash', LargeBinary, nullable=True),
Column('signature', LargeBinary, nullable=True),
Column('signature_digest', LargeBinary, nullable=True),
Column('is_signature_valid', Boolean, server_default='0'),
2020-06-05 06:35:22 +02:00
)
2020-06-19 20:28:34 +02:00
Takeover = Table(
'takeover', metadata,
Column('normalized', Text),
Column('claim_hash', LargeBinary, ForeignKey(TXO.columns.claim_hash)),
Column('height', Integer),
2020-05-01 15:29:44 +02:00
)