-
Notifications
You must be signed in to change notification settings - Fork 44
feat: add is_extended_promotional column to components (#92) #130
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,52 @@ | ||
| import { sql } from "kysely" | ||
| import type { DbOptimizationSpec } from "./types" | ||
| import type { KyselyDatabaseInstance } from "../kysely-types" | ||
|
|
||
| export const componentExtendedPromotionalColumn: DbOptimizationSpec = { | ||
| name: "col_components_is_extended_promotional", | ||
| description: | ||
| "Add is_extended_promotional column to components table for extended promotional parts", | ||
|
|
||
| async checkIfAdded(db: KyselyDatabaseInstance) { | ||
| const result = await sql` | ||
| SELECT name FROM pragma_table_info('components') | ||
| WHERE name = 'is_extended_promotional' | ||
| `.execute(db) | ||
|
|
||
| return result.rows.length > 0 | ||
| }, | ||
|
|
||
| async execute(db: KyselyDatabaseInstance) { | ||
| // Add the column to the components table | ||
| await sql` | ||
| ALTER TABLE components ADD COLUMN is_extended_promotional INTEGER NOT NULL DEFAULT 0 | ||
| `.execute(db) | ||
|
|
||
| // Create an index for efficient filtering | ||
| await sql` | ||
| CREATE INDEX IF NOT EXISTS idx_components_is_extended_promotional | ||
| ON components(is_extended_promotional) | ||
| `.execute(db) | ||
|
|
||
| // Recreate the v_components view to include the new column | ||
| const viewResult = await sql` | ||
| SELECT sql FROM sqlite_master WHERE type='view' AND name='v_components' | ||
| `.execute(db) | ||
|
|
||
| if (viewResult.rows.length > 0) { | ||
| const originalSql = (viewResult.rows[0] as any).sql as string | ||
|
|
||
| await sql`DROP VIEW IF EXISTS v_components`.execute(db) | ||
|
|
||
| // Insert the new column reference before the FROM clause | ||
| const fromIndex = originalSql.toUpperCase().indexOf("\nFROM") | ||
| if (fromIndex > -1) { | ||
| const newSql = `${originalSql.slice(0, fromIndex)},\n components.is_extended_promotional${originalSql.slice(fromIndex)}` | ||
| await sql.raw(newSql).execute(db) | ||
| } else { | ||
| // Fallback: just re-execute original if we can't parse it | ||
| await sql.raw(originalSql).execute(db) | ||
| } | ||
| } | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,25 @@ test("GET /components/list with json param returns component data", async () => | |
| expect(res.data).toHaveProperty("components") | ||
| expect(Array.isArray(res.data.components)).toBe(true) | ||
| }) | ||
|
|
||
| test("GET /components/list returns is_extended_promotional field", async () => { | ||
| const { axios } = await getTestServer() | ||
| const res = await axios.get("/components/list?json=true") | ||
| expect(res.data).toHaveProperty("components") | ||
| expect(Array.isArray(res.data.components)).toBe(true) | ||
|
|
||
| if (res.data.components.length > 0) { | ||
| const component = res.data.components[0] | ||
| expect(component).toHaveProperty("is_extended_promotional") | ||
| expect(typeof component.is_extended_promotional).toBe("boolean") | ||
| } | ||
| }) | ||
|
|
||
| test("GET /components/list with is_extended_promotional filter", async () => { | ||
| const { axios } = await getTestServer() | ||
| const res = await axios.get( | ||
| "/components/list?json=true&is_extended_promotional=true", | ||
| ) | ||
| expect(res.data).toHaveProperty("components") | ||
| expect(Array.isArray(res.data.components)).toBe(true) | ||
| }) | ||
|
Comment on lines
+11
to
+31
Contributor
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. This test file violates the rule that a *.test.ts file may have AT MOST one test(...) function. The file now contains multiple test() functions (the original test plus the two new ones added in lines 11-22 and 24-31). The file should be split into multiple numbered files like list1.test.ts, list2.test.ts, etc., with each file containing only one test() function. Spotted by Graphite (based on custom rule: Custom rule) |
||
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 test file violates the rule that a *.test.ts file may have AT MOST one test(...) function. The file now contains multiple test() functions (the original tests plus the two new ones added in lines 82-94 and 96-102). The file should be split into multiple numbered files like search1.test.ts, search2.test.ts, etc., with each file containing only one test() function.
Spotted by Graphite (based on custom rule: Custom rule)

Is this helpful? React 👍 or 👎 to let us know.