(args: string[])
| 117 | } |
| 118 | |
| 119 | export default async function dbCheckScoping(args: string[]): Promise<void> { |
| 120 | const parsed = parseArgs(args); |
| 121 | |
| 122 | if (parsed.help === "true") { |
| 123 | console.log(`Usage: pnpm action db-check-scoping [options] |
| 124 | |
| 125 | Options: |
| 126 | --db <path> Path to SQLite database (default: data/app.db) |
| 127 | --require-org Also check for org_id column (for multi-org apps) |
| 128 | --format json Output as JSON |
| 129 | --help Show this help message`); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | const requireOrg = parsed["require-org"] === "true"; |
| 134 | const format = parsed.format; |
| 135 | |
| 136 | // Resolve database URL |
| 137 | let url: string; |
| 138 | if (parsed.db) { |
| 139 | url = "file:" + path.resolve(parsed.db); |
| 140 | } else if (getDatabaseUrl()) { |
| 141 | url = getDatabaseUrl(); |
| 142 | } else { |
| 143 | url = "file:" + path.resolve(process.cwd(), "data", "app.db"); |
| 144 | } |
| 145 | |
| 146 | let allColumns: TableColumn[]; |
| 147 | |
| 148 | if (isPostgresUrl(url)) { |
| 149 | const { default: pg } = await import("postgres"); |
| 150 | const pgSql = pg(url); |
| 151 | try { |
| 152 | allColumns = await discoverColumnsPostgres(pgSql); |
| 153 | } finally { |
| 154 | await pgSql.end(); |
| 155 | } |
| 156 | } else { |
| 157 | const client = createClient({ |
| 158 | url, |
| 159 | authToken: getDatabaseAuthToken(), |
| 160 | }); |
| 161 | try { |
| 162 | allColumns = await discoverColumnsSqlite(client); |
| 163 | } finally { |
| 164 | client.close(); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | const results = validate(allColumns, requireOrg); |
| 169 | |
| 170 | if (format === "json") { |
| 171 | console.log(JSON.stringify({ tables: results }, null, 2)); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | const withIssues = results.filter((r) => r.issues.length > 0); |
| 176 | const ok = results.filter((r) => r.issues.length === 0); |
nothing calls this directly
no test coverage detected