/**
* Categories module table. Module-owned naming: categories_
.
*/
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
export const up = (pgm) => {
pgm.sql(`
CREATE TABLE categories_categories (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
parent_id uuid REFERENCES categories_categories(id) ON DELETE RESTRICT,
name text NOT NULL,
slug text NOT NULL UNIQUE,
seo_title text,
seo_description text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
CONSTRAINT categories_categories_no_self_parent CHECK (parent_id IS NULL OR parent_id <> id)
)
`);
pgm.sql('CREATE INDEX categories_categories_parent_id_idx ON categories_categories (parent_id)');
pgm.sql('CREATE INDEX categories_categories_slug_idx ON categories_categories (slug)');
};
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
export const down = (pgm) => {
pgm.sql('DROP TABLE IF EXISTS categories_categories');
};