feat(ADM-018): completed feature
This commit is contained in:
45
project/migrations/008_catalog_variants_rich_data.js
Normal file
45
project/migrations/008_catalog_variants_rich_data.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Catalog product variants and rich product data.
|
||||
*/
|
||||
|
||||
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
|
||||
export const up = (pgm) => {
|
||||
pgm.sql(`
|
||||
CREATE TABLE catalog_product_variants (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
product_id uuid NOT NULL REFERENCES catalog_products(id) ON DELETE CASCADE,
|
||||
sku text NOT NULL UNIQUE,
|
||||
ean text UNIQUE,
|
||||
attributes jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
)
|
||||
`);
|
||||
pgm.sql(
|
||||
'CREATE INDEX catalog_product_variants_product_id_idx ON catalog_product_variants (product_id)',
|
||||
);
|
||||
|
||||
pgm.sql(`
|
||||
CREATE TABLE catalog_product_rich_data (
|
||||
product_id uuid PRIMARY KEY REFERENCES catalog_products(id) ON DELETE CASCADE,
|
||||
ingredients text,
|
||||
allergens text[] NOT NULL DEFAULT ARRAY[]::text[],
|
||||
nutrition jsonb,
|
||||
nutrition_source text,
|
||||
is_organic boolean NOT NULL DEFAULT false,
|
||||
organic_certification text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT catalog_product_rich_data_nutrition_source_check
|
||||
CHECK (nutrition_source IS NULL OR nutrition_source IN ('manual', 'manufacturer', 'openfoodfacts')),
|
||||
CONSTRAINT catalog_product_rich_data_nutrition_source_required_check
|
||||
CHECK (nutrition IS NULL OR nutrition_source IS NOT NULL)
|
||||
)
|
||||
`);
|
||||
};
|
||||
|
||||
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
|
||||
export const down = (pgm) => {
|
||||
pgm.sql('DROP TABLE IF EXISTS catalog_product_rich_data');
|
||||
pgm.sql('DROP TABLE IF EXISTS catalog_product_variants');
|
||||
};
|
||||
Reference in New Issue
Block a user