@bolvrk/engine-sqlite 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +105 -0
- package/README.md +26 -0
- package/dist/engine.d.ts +24 -0
- package/dist/helpers.d.ts +77 -0
- package/dist/index-m4sztshc.js +615 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1421 -0
- package/dist/metas/index.d.ts +53 -0
- package/dist/metas/index.js +80 -0
- package/dist/parser.d.ts +33 -0
- package/dist/rule.d.ts +17 -0
- package/dist/rules/add-column.d.ts +13 -0
- package/dist/rules/dml-and-maintenance.d.ts +7 -0
- package/dist/rules/index.d.ts +5 -0
- package/dist/rules/indexes-and-types.d.ts +7 -0
- package/dist/rules/performance.d.ts +11 -0
- package/dist/rules/rebuild-pragmas.d.ts +11 -0
- package/dist/rules/schema-and-transactions.d.ts +23 -0
- package/dist/rules/table-shape.d.ts +5 -0
- package/package.json +45 -0
- package/src/engine.ts +89 -0
- package/src/helpers.ts +254 -0
- package/src/index.ts +5 -0
- package/src/metas/LICENSE +202 -0
- package/src/metas/index.ts +598 -0
- package/src/parser.ts +68 -0
- package/src/rule.ts +36 -0
- package/src/rules/LICENSE +202 -0
- package/src/rules/add-column.ts +180 -0
- package/src/rules/dml-and-maintenance.ts +75 -0
- package/src/rules/index.ts +18 -0
- package/src/rules/indexes-and-types.ts +99 -0
- package/src/rules/performance.ts +207 -0
- package/src/rules/rebuild-pragmas.ts +142 -0
- package/src/rules/schema-and-transactions.ts +446 -0
- package/src/rules/table-shape.ts +76 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 Bolvrk
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @bolvrk/engine-sqlite
|
|
2
|
+
|
|
3
|
+
SQLite migration danger rules for [Bolvrk](https://bolvrk.com) — the `SL###` corpus,
|
|
4
|
+
over a real SQLite grammar ([sql-parser-cst](https://github.com/nene/sql-parser-cst)),
|
|
5
|
+
never regex.
|
|
6
|
+
|
|
7
|
+
**Alpha.** Static (tier 1) rules only, behind `--engine=sqlite` in the CLI:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx bolvrk check migrations/*.sql --engine=sqlite
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The rules cover the forms of `ALTER TABLE ADD COLUMN` SQLite refuses, the whole-table
|
|
14
|
+
rewrite `DROP COLUMN` performs, the twelve-step table rebuild and the pragmas around
|
|
15
|
+
it, unbounded writes, `VACUUM` and `REINDEX`, index builds under the single write lock,
|
|
16
|
+
the rowid traps (`INT PRIMARY KEY`, `AUTOINCREMENT`, nullable keys), STRICT and child-key indexes, dependent views and triggers, deferred and nested transactions, non-deterministic index expressions and `ATTACH`. The credential rules `check` runs on Postgres (BC003, BC004) run here too. Every rule ships fixture
|
|
17
|
+
migrations in both directions, and every "SQLite refuses this" claim is re-proven against
|
|
18
|
+
a real SQLite in the test suite.
|
|
19
|
+
|
|
20
|
+
Same findings contract as the Postgres engine (`engine: "sqlite"` on the report).
|
|
21
|
+
Inline suppressions (`-- bolvrk-ignore SL001: reason`) work the same way.
|
|
22
|
+
|
|
23
|
+
Rule reference: [docs/](docs/README.md).
|
|
24
|
+
|
|
25
|
+
Licensing follows `@bolvrk/engine`: the rules and their metadata (`src/rules/`,
|
|
26
|
+
`src/metas/`) are Apache-2.0; the parser wrapper and check pipeline are FSL-1.1-ALv2.
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CheckReport } from "@bolvrk/engine";
|
|
2
|
+
import type { SlRule } from "./rule";
|
|
3
|
+
export interface SqliteCheckOptions {
|
|
4
|
+
/** Override the rule set (used by tests); defaults to the full SL corpus. */
|
|
5
|
+
rules?: readonly SlRule[];
|
|
6
|
+
/** Skip the credential rules (BC003, BC004) that `check` runs on every engine. Default: run them. */
|
|
7
|
+
skipCredentials?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** The credential rules `bolvrk check` runs on Postgres and, through here, on SQLite too — text-level, engine-neutral. */
|
|
10
|
+
export declare const CREDENTIAL_RULE_IDS: ReadonlySet<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Run a SQLite migration through the SL corpus. Same findings contract as
|
|
13
|
+
* the Postgres engine, same determinism guarantee: identical input produces
|
|
14
|
+
* byte-identical report JSON. Static (tier 1) only — SQLite has no server
|
|
15
|
+
* to introspect, and the rules that would want a live file (table sizes)
|
|
16
|
+
* say so in their message instead.
|
|
17
|
+
*
|
|
18
|
+
* Inline suppressions (`-- bolvrk-ignore SL001: reason`) work exactly as on
|
|
19
|
+
* Postgres: the engine's own collector reads the comment lines between
|
|
20
|
+
* statements as the parser located them.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkSqliteMigration(sql: string, options?: SqliteCheckOptions): CheckReport;
|
|
23
|
+
/** 1-based start line of each statement — for SARIF locations. */
|
|
24
|
+
export declare function sqliteStatementStartLines(sql: string): number[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CST helpers the SL rules are written against: one implementation of
|
|
3
|
+
* "which table does this statement touch", "is this statement inside an
|
|
4
|
+
* explicit transaction", and the shape of a column definition.
|
|
5
|
+
*/
|
|
6
|
+
import type { Node } from "sql-parser-cst";
|
|
7
|
+
import type { ParsedSqliteMigration, ParsedSqliteStatement } from "./parser";
|
|
8
|
+
type AnyNode = Record<string, any>;
|
|
9
|
+
/** Unquoted name of an identifier or a `schema.name` member expression. */
|
|
10
|
+
export declare function nameOf(node: AnyNode | undefined | null): string | undefined;
|
|
11
|
+
/** Items of a `list_expr`, or the single node when the parser did not wrap one. */
|
|
12
|
+
export declare function items(node: AnyNode | undefined | null): AnyNode[];
|
|
13
|
+
/** The ALTER TABLE actions of a statement (empty for anything else). */
|
|
14
|
+
export declare function alterActions(stmt: ParsedSqliteStatement): AnyNode[];
|
|
15
|
+
/** Column definitions added by `ALTER TABLE ... ADD [COLUMN]` in this statement. */
|
|
16
|
+
export declare function addedColumns(stmt: ParsedSqliteStatement): AnyNode[];
|
|
17
|
+
/** Column definitions of a CREATE TABLE statement (constraints declared at table level excluded). */
|
|
18
|
+
export declare function createdColumns(stmt: ParsedSqliteStatement): AnyNode[];
|
|
19
|
+
/** Table-level constraints of a CREATE TABLE statement. */
|
|
20
|
+
export declare function tableConstraints(stmt: ParsedSqliteStatement): AnyNode[];
|
|
21
|
+
/** A column definition's constraint of the given CST type, if any. */
|
|
22
|
+
export declare function constraintOf(column: AnyNode, type: string): AnyNode | undefined;
|
|
23
|
+
/** Keyword name(s) of a data type node, uppercased and joined — `INT`, `INTEGER`, `VARCHAR`. */
|
|
24
|
+
export declare function dataTypeName(column: AnyNode): string;
|
|
25
|
+
/** Table options of CREATE TABLE (`WITHOUT ROWID`, `STRICT`), uppercased. */
|
|
26
|
+
export declare function tableOptions(stmt: ParsedSqliteStatement): string[];
|
|
27
|
+
/** The primary table a statement targets, if any. */
|
|
28
|
+
export declare function tableOf(stmt: ParsedSqliteStatement): string | undefined;
|
|
29
|
+
/** Tables dropped by a DROP TABLE statement. */
|
|
30
|
+
export declare function droppedTables(stmt: ParsedSqliteStatement): string[];
|
|
31
|
+
/** True when `table` is created by an earlier statement of this migration. */
|
|
32
|
+
export declare function tableCreatedInMigration(migration: ParsedSqliteMigration, beforeIndex: number, table: string): boolean;
|
|
33
|
+
/** One "drop, then rename another table onto the name" pair in a migration. */
|
|
34
|
+
export interface TableRebuild {
|
|
35
|
+
/** The DROP TABLE statement. */
|
|
36
|
+
drop: ParsedSqliteStatement;
|
|
37
|
+
/** The ALTER TABLE ... RENAME TO statement that restores the dropped name. */
|
|
38
|
+
rename: ParsedSqliteStatement;
|
|
39
|
+
/** The name being rebuilt. */
|
|
40
|
+
table: string;
|
|
41
|
+
/** The table renamed onto it. */
|
|
42
|
+
replacement: string;
|
|
43
|
+
/** True when the replacement was created earlier in this file — the documented recipe rather than a swap of two live tables. */
|
|
44
|
+
replacementCreatedHere: boolean;
|
|
45
|
+
/** An INSERT into the replacement that reads from the old table, issued before the DROP. */
|
|
46
|
+
copy?: ParsedSqliteStatement;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Every rebuild in the migration: DROP TABLE x followed, later in the file,
|
|
50
|
+
* by ALTER TABLE y RENAME TO x. The interim table's name plays no part —
|
|
51
|
+
* the match is structural, on the dropped name coming back as a rename
|
|
52
|
+
* target. Cross-file rebuilds are invisible; the engine sees one file.
|
|
53
|
+
*/
|
|
54
|
+
export declare function tableRebuilds(migration: ParsedSqliteMigration): TableRebuild[];
|
|
55
|
+
/** The WHERE clause of an UPDATE / DELETE, if present. */
|
|
56
|
+
export declare function hasWhere(stmt: ParsedSqliteStatement): boolean;
|
|
57
|
+
export interface PragmaRead {
|
|
58
|
+
name: string;
|
|
59
|
+
/** Assigned value, lowercased (`off`, `on`, `0`, `wal`); undefined for a bare query like `PRAGMA foreign_key_check`. */
|
|
60
|
+
value?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Name and value of a PRAGMA statement; undefined for anything else. */
|
|
63
|
+
export declare function pragmaOf(stmt: ParsedSqliteStatement): PragmaRead | undefined;
|
|
64
|
+
/** SQLite's boolean spellings for a pragma value. */
|
|
65
|
+
export declare function pragmaIsOff(value: string | undefined): boolean;
|
|
66
|
+
export declare function pragmaIsOn(value: string | undefined): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* For each statement, whether it runs inside an explicit transaction opened
|
|
69
|
+
* earlier in the file (BEGIN ... COMMIT/END/ROLLBACK). Statements before any
|
|
70
|
+
* BEGIN, or after the matching COMMIT, are "autocommit" from the file's point
|
|
71
|
+
* of view — a migration runner may still wrap the whole file, which is why
|
|
72
|
+
* rules that depend on this say so in their message.
|
|
73
|
+
*/
|
|
74
|
+
export declare function insideTransaction(migration: ParsedSqliteMigration): boolean[];
|
|
75
|
+
/** Depth-first descendants of a CST node matching a predicate. */
|
|
76
|
+
export declare function descendants(node: Node | AnyNode | undefined, predicate: (node: AnyNode) => boolean): AnyNode[];
|
|
77
|
+
export {};
|