Skip to content

Commit 514bfe2

Browse files
committed
sqldb: fix sqlfluff complaints for migrations
1 parent 04be122 commit 514bfe2

File tree

56 files changed

+1142
-814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1142
-814
lines changed

.sqlfluff

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[sqlfluff]
2+
dialect = sqlite
3+
templater = raw
4+
5+
processes = -1
6+
7+
exclude_rules = AM04, AM05, AL05, ST06
8+
9+
warnings = RF04
10+
11+
large_file_skip_byte_limit = 50000
12+
13+
[sqlfluff:indentation]
14+
tab_space_size = 4
15+
indented_joins = False
16+
indented_on_contents = True
17+
allow_implicit_indents = False
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CREATE TABLE IF NOT EXISTS macaroons (
22
id BLOB PRIMARY KEY,
3-
root_key BLOB NOT NULL
3+
root_key BLOB NOT NULL
44
);

tapdb/sqlc/migrations/000002_assets.up.sql

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS genesis_points (
2828
-- TODO(roasbeef): just need the input index here instead?
2929
prev_out BLOB UNIQUE NOT NULL,
3030

31-
anchor_tx_id BIGINT REFERENCES chain_txns(txn_id)
31+
anchor_tx_id BIGINT REFERENCES chain_txns (txn_id)
3232
);
3333

3434
-- assets_meta is a table that holds all the metadata information for genesis
@@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS genesis_points (
3737
CREATE TABLE IF NOT EXISTS assets_meta (
3838
meta_id INTEGER PRIMARY KEY,
3939

40-
meta_data_hash BLOB UNIQUE CHECK(length(meta_data_hash) = 32),
40+
meta_data_hash BLOB UNIQUE CHECK (length(meta_data_hash) = 32),
4141

4242
-- TODO(roasbeef): also have other opque blob here for future fields?
4343
meta_data_blob BLOB,
@@ -56,17 +56,17 @@ CREATE TABLE IF NOT EXISTS genesis_assets (
5656

5757
asset_tag TEXT NOT NULL,
5858

59-
meta_data_id BIGINT REFERENCES assets_meta(meta_id),
59+
meta_data_id BIGINT REFERENCES assets_meta (meta_id),
6060

6161
output_index INTEGER NOT NULL,
6262

6363
-- TODO(roasbeef): make into an enum? also add into asset_id generation?
6464
-- BIP PR
6565
asset_type SMALLINT NOT NULL,
6666

67-
genesis_point_id BIGINT NOT NULL REFERENCES genesis_points(genesis_id)
67+
genesis_point_id BIGINT NOT NULL REFERENCES genesis_points (genesis_id)
6868
);
69-
CREATE INDEX IF NOT EXISTS asset_ids on genesis_assets(asset_id);
69+
CREATE INDEX IF NOT EXISTS asset_ids ON genesis_assets (asset_id);
7070

7171
-- internal_keys is the set of public keys managed and used by the daemon. The
7272
-- full KeyLocator is stored so we can use these keys without actually storing
@@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS internal_keys (
7676

7777
-- We'll always store the full 33-byte key on disk, to make sure we're
7878
-- retaining full information.
79-
raw_key BLOB NOT NULL UNIQUE CHECK(length(raw_key) = 33),
79+
raw_key BLOB NOT NULL UNIQUE CHECK (length(raw_key) = 33),
8080

8181
key_family INTEGER NOT NULL,
8282

@@ -90,15 +90,16 @@ CREATE TABLE IF NOT EXISTS internal_keys (
9090
CREATE TABLE IF NOT EXISTS asset_groups (
9191
group_id INTEGER PRIMARY KEY,
9292

93-
tweaked_group_key BLOB UNIQUE NOT NULL CHECK(length(tweaked_group_key) = 33),
93+
tweaked_group_key BLOB UNIQUE NOT NULL
94+
CHECK (length(tweaked_group_key) = 33),
9495

9596
tapscript_root BLOB,
9697

9798
-- TODO(roasbeef): also need to mix in output index here? to derive the
9899
-- genesis key?
99-
internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id),
100+
internal_key_id BIGINT NOT NULL REFERENCES internal_keys (key_id),
100101

101-
genesis_point_id BIGINT NOT NULL REFERENCES genesis_points(genesis_id)
102+
genesis_point_id BIGINT NOT NULL REFERENCES genesis_points (genesis_id)
102103
);
103104

104105
-- asset_group_witnesses stores the set of signatures/witness stacks for an
@@ -114,9 +115,10 @@ CREATE TABLE IF NOT EXISTS asset_group_witnesses (
114115
witness_stack BLOB NOT NULL,
115116

116117
-- TODO(roasbeef): not needed since already in assets row?
117-
gen_asset_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id) UNIQUE,
118+
gen_asset_id BIGINT NOT NULL
119+
REFERENCES genesis_assets (gen_asset_id) UNIQUE,
118120

119-
group_key_id BIGINT NOT NULL REFERENCES asset_groups(group_id)
121+
group_key_id BIGINT NOT NULL REFERENCES asset_groups (group_id)
120122
);
121123

122124
-- managed_utxos is the set of UTXOs managed by tapd. These UTXOs may commit
@@ -132,10 +134,10 @@ CREATE TABLE IF NOT EXISTS managed_utxos (
132134
-- 64 bit issues?
133135
amt_sats BIGINT NOT NULL,
134136

135-
internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id),
137+
internal_key_id BIGINT NOT NULL REFERENCES internal_keys (key_id),
136138

137139
-- The Taproot Asset root commitment hash.
138-
taproot_asset_root BLOB NOT NULL CHECK(length(taproot_asset_root) = 32),
140+
taproot_asset_root BLOB NOT NULL CHECK (length(taproot_asset_root) = 32),
139141

140142
-- The serialized tapscript sibling preimage. If this is empty then the
141143
-- Taproot Asset root commitment is equal to the merkle_root below.
@@ -145,16 +147,16 @@ CREATE TABLE IF NOT EXISTS managed_utxos (
145147
-- corresponds to the Taproot Asset root commitment hash.
146148
--
147149
-- TODO(roasbeef): can then reconstruct on start up to ensure matches up
148-
merkle_root BLOB NOT NULL CHECK(length(merkle_root) = 32),
150+
merkle_root BLOB NOT NULL CHECK (length(merkle_root) = 32),
149151

150-
txn_id BIGINT NOT NULL REFERENCES chain_txns(txn_id),
152+
txn_id BIGINT NOT NULL REFERENCES chain_txns (txn_id),
151153

152154
-- The identity of the application that currently has a lease on this UTXO.
153155
-- If NULL, then the UTXO is not currently leased. A lease means that the
154156
-- UTXO is being reserved/locked to be spent in an upcoming transaction and
155157
-- that it should not be available for coin selection through any of the
156158
-- wallet RPCs.
157-
lease_owner BLOB CHECK(length(lease_owner) = 32),
159+
lease_owner BLOB CHECK (length(lease_owner) = 32),
158160

159161
-- The absolute expiry of the lease in seconds as a Unix timestamp. If the
160162
-- expiry is NULL or the timestamp is in the past, then the lease is not
@@ -167,11 +169,12 @@ CREATE TABLE IF NOT EXISTS script_keys (
167169

168170
-- The actual internal key here that we hold the private key for. Applying
169171
-- the tweak to this gives us the tweaked_script_key.
170-
internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id),
172+
internal_key_id BIGINT NOT NULL REFERENCES internal_keys (key_id),
171173

172174
-- The script key after applying the tweak. This is what goes directly in
173175
-- the asset TLV.
174-
tweaked_script_key BLOB NOT NULL UNIQUE CHECK(length(tweaked_script_key) = 33),
176+
tweaked_script_key BLOB NOT NULL UNIQUE
177+
CHECK (length(tweaked_script_key) = 33),
175178

176179
-- An optional tweak for the script_key. If NULL, the raw_key may be
177180
-- tweaked BIP-0086 style.
@@ -185,15 +188,15 @@ CREATE TABLE IF NOT EXISTS script_keys (
185188
-- spend the asset.
186189
CREATE TABLE IF NOT EXISTS assets (
187190
asset_id INTEGER PRIMARY KEY,
188-
189-
genesis_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id),
191+
192+
genesis_id BIGINT NOT NULL REFERENCES genesis_assets (gen_asset_id),
190193

191194
version INTEGER NOT NULL,
192195

193-
script_key_id BIGINT NOT NULL REFERENCES script_keys(script_key_id),
196+
script_key_id BIGINT NOT NULL REFERENCES script_keys (script_key_id),
194197

195198
-- TODO(roasbeef): don't need this after all?
196-
asset_group_witness_id BIGINT REFERENCES asset_group_witnesses(witness_id),
199+
asset_group_witness_id BIGINT REFERENCES asset_group_witnesses (witness_id),
197200

198201
-- TODO(roasbeef): make into enum?
199202
script_version INTEGER NOT NULL,
@@ -210,15 +213,15 @@ CREATE TABLE IF NOT EXISTS assets (
210213

211214
split_commitment_root_value BIGINT,
212215

213-
anchor_utxo_id BIGINT REFERENCES managed_utxos(utxo_id),
214-
216+
anchor_utxo_id BIGINT REFERENCES managed_utxos (utxo_id),
217+
215218
-- A boolean that indicates that the asset was spent. This is only
216219
-- set for assets that were transferred in an active manner (as part of an
217220
-- user initiated transfer). Passive assets that are just re-anchored are
218221
-- updated in-place.
219222
spent BOOLEAN NOT NULL DEFAULT FALSE,
220-
221-
UNIQUE(asset_id, genesis_id, script_key_id)
223+
224+
UNIQUE (asset_id, genesis_id, script_key_id)
222225
);
223226

224227
-- asset_witnesses stores the set of input witnesses for the latest state of an
@@ -227,7 +230,7 @@ CREATE TABLE IF NOT EXISTS assets (
227230
CREATE TABLE IF NOT EXISTS asset_witnesses (
228231
witness_id INTEGER PRIMARY KEY,
229232

230-
asset_id BIGINT NOT NULL REFERENCES assets(asset_id) ON DELETE CASCADE,
233+
asset_id BIGINT NOT NULL REFERENCES assets (asset_id) ON DELETE CASCADE,
231234

232235
prev_out_point BLOB NOT NULL,
233236

@@ -247,7 +250,7 @@ CREATE TABLE IF NOT EXISTS asset_proofs (
247250

248251
-- We enforce that this value is unique so we can use an UPSERT to update a
249252
-- proof file that already exists.
250-
asset_id BIGINT NOT NULL REFERENCES assets(asset_id) UNIQUE,
253+
asset_id BIGINT NOT NULL REFERENCES assets (asset_id) UNIQUE,
251254

252255
-- TODO(roasbef): store the merkle root separately? then can refer back to
253256
-- for all other files
@@ -260,7 +263,8 @@ CREATE TABLE IF NOT EXISTS asset_proofs (
260263
-- minting transaction which once signed and broadcast will actually create the
261264
-- assets.
262265
CREATE TABLE IF NOT EXISTS asset_minting_batches (
263-
batch_id INTEGER PRIMARY KEY REFERENCES internal_keys(key_id),
266+
batch_id INTEGER PRIMARY KEY -- noqa: LL01
267+
REFERENCES internal_keys (key_id), -- TODO(guggero): Use BIGINT.
264268

265269
-- TODO(roasbeef): make into proper enum table or use check to ensure
266270
-- proper values
@@ -270,13 +274,14 @@ CREATE TABLE IF NOT EXISTS asset_minting_batches (
270274

271275
change_output_index INTEGER,
272276

273-
genesis_id BIGINT REFERENCES genesis_points(genesis_id),
277+
genesis_id BIGINT REFERENCES genesis_points (genesis_id),
274278

275279
height_hint INTEGER NOT NULL,
276280

277281
creation_time_unix TIMESTAMP NOT NULL
278282
);
279-
CREATE INDEX IF NOT EXISTS batch_state_lookup on asset_minting_batches (batch_state);
283+
CREATE INDEX IF NOT EXISTS batch_state_lookup
284+
ON asset_minting_batches (batch_state);
280285

281286
-- asset_seedlings are budding assets: the contain the base asset information
282287
-- need to create an asset, but doesn't yet have a genesis point.
@@ -293,15 +298,15 @@ CREATE TABLE IF NOT EXISTS asset_seedlings (
293298

294299
asset_supply BIGINT NOT NULL,
295300

296-
asset_meta_id BIGINT NOT NULL REFERENCES assets_meta(meta_id),
301+
asset_meta_id BIGINT NOT NULL REFERENCES assets_meta (meta_id),
297302

298303
emission_enabled BOOLEAN NOT NULL,
299304

300-
batch_id BIGINT NOT NULL REFERENCES asset_minting_batches(batch_id),
305+
batch_id BIGINT NOT NULL REFERENCES asset_minting_batches (batch_id),
301306

302-
group_genesis_id BIGINT REFERENCES genesis_assets(gen_asset_id),
307+
group_genesis_id BIGINT REFERENCES genesis_assets (gen_asset_id),
303308

304-
group_anchor_id BIGINT REFERENCES asset_seedlings(seedling_id)
309+
group_anchor_id BIGINT REFERENCES asset_seedlings (seedling_id)
305310
);
306311

307312
-- TODO(roasbeef): need on delete cascade for all these?
@@ -313,31 +318,45 @@ CREATE TABLE IF NOT EXISTS asset_seedlings (
313318
-- points, to the internal key that reference the batch, then restricted
314319
-- for internal keys that match our main batch key.
315320
CREATE VIEW genesis_info_view AS
316-
SELECT
317-
gen_asset_id, asset_id, asset_tag, assets_meta.meta_data_hash meta_hash,
318-
output_index, asset_type, genesis_points.prev_out prev_out, block_height
319-
FROM genesis_assets
320-
-- We do a LEFT JOIN here, as not every asset has a set of
321-
-- metadata that matches the asset.
322-
LEFT JOIN assets_meta
323-
ON genesis_assets.meta_data_id = assets_meta.meta_id
324-
JOIN genesis_points
325-
ON genesis_assets.genesis_point_id = genesis_points.genesis_id
326-
LEFT JOIN chain_txns
327-
ON genesis_points.anchor_tx_id = chain_txns.txn_id;
321+
SELECT
322+
genesis_assets.gen_asset_id,
323+
genesis_assets.asset_id,
324+
genesis_assets.asset_tag,
325+
assets_meta.meta_data_hash AS meta_hash,
326+
genesis_assets.output_index,
327+
genesis_assets.asset_type,
328+
genesis_points.prev_out,
329+
chain_txns.block_height
330+
FROM genesis_assets
331+
-- We do a LEFT JOIN here, as not every asset has a set of
332+
-- metadata that matches the asset.
333+
LEFT JOIN assets_meta
334+
ON genesis_assets.meta_data_id = assets_meta.meta_id
335+
JOIN genesis_points
336+
ON genesis_assets.genesis_point_id = genesis_points.genesis_id
337+
LEFT JOIN chain_txns
338+
ON genesis_points.anchor_tx_id = chain_txns.txn_id;
328339

329340
-- This view is used to perform a series of joins that allow us to extract
330341
-- the group key information, as well as the group sigs for the series of
331342
-- assets we care about. We obtain only the assets found in the batch
332343
-- above, with the WHERE query at the bottom.
333344
CREATE VIEW key_group_info_view AS
334-
SELECT
335-
witness_id, gen_asset_id, witness_stack, tapscript_root,
336-
tweaked_group_key, raw_key, key_index, key_family,
337-
substr(tweaked_group_key, 2) AS x_only_group_key
338-
FROM asset_group_witnesses wit
339-
JOIN asset_groups groups
340-
ON wit.group_key_id = groups.group_id
341-
JOIN internal_keys keys
342-
ON keys.key_id = groups.internal_key_id
343-
WHERE wit.gen_asset_id IN (SELECT gen_asset_id FROM genesis_info_view);
345+
SELECT
346+
wit.witness_id,
347+
wit.gen_asset_id,
348+
wit.witness_stack,
349+
grp.tapscript_root,
350+
grp.tweaked_group_key,
351+
keys.raw_key,
352+
keys.key_index,
353+
keys.key_family,
354+
substr(grp.tweaked_group_key, 2) AS x_only_group_key
355+
FROM asset_group_witnesses AS wit
356+
JOIN asset_groups AS grp
357+
ON wit.group_key_id = grp.group_id
358+
JOIN internal_keys AS keys
359+
ON grp.internal_key_id = keys.key_id
360+
WHERE wit.gen_asset_id IN (
361+
SELECT giv.gen_asset_id FROM genesis_info_view AS giv
362+
);

tapdb/sqlc/migrations/000003_addrs.up.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ CREATE TABLE IF NOT EXISTS addrs (
1212

1313
-- genesis_asset_id points to the asset genesis of the asset we want to
1414
-- send/recv.
15-
genesis_asset_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id),
15+
genesis_asset_id BIGINT NOT NULL REFERENCES genesis_assets (gen_asset_id),
1616

1717
-- group_key is the raw blob of the group key. For assets w/o a group key,
1818
-- this field will be NULL.
1919
group_key BLOB,
2020

2121
-- script_key_id points to the internal key that we created to serve as the
2222
-- script key to be able to receive this asset.
23-
script_key_id BIGINT NOT NULL REFERENCES script_keys(script_key_id),
23+
script_key_id BIGINT NOT NULL REFERENCES script_keys (script_key_id),
2424

2525
-- taproot_key_id points to the internal key that we'll use to serve as the
2626
-- taproot internal key to receive this asset.
27-
taproot_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id),
27+
taproot_key_id BIGINT NOT NULL REFERENCES internal_keys (key_id),
2828

2929
-- tapscript_sibling is the serialized tapscript sibling preimage that
3030
-- should be committed to in the taproot output alongside the Taproot Asset
@@ -34,10 +34,12 @@ CREATE TABLE IF NOT EXISTS addrs (
3434
-- taproot_output_key is the tweaked taproot output key that assets must
3535
-- be sent to on chain to be received, represented as a 32-byte x-only
3636
-- public key.
37-
taproot_output_key BLOB NOT NULL UNIQUE CHECK(length(taproot_output_key) = 32),
37+
taproot_output_key BLOB NOT NULL UNIQUE CHECK (
38+
length(taproot_output_key) = 32
39+
),
3840

3941
-- amount is the amount of asset we want to receive.
40-
amount BIGINT NOT NULL,
42+
amount BIGINT NOT NULL,
4143

4244
-- asset_type is the type of asset we want to receive.
4345
asset_type SMALLINT NOT NULL,

0 commit comments

Comments
 (0)