### Install dependencies and start the production build Source: https://stackrender.io/docs/self-hosted Installs project dependencies and starts the production build. Run these commands in the cloned repository directory. ```bash npm install npm run start ``` -------------------------------- ### Install dependencies and start the development server Source: https://stackrender.io/docs/self-hosted Installs project dependencies and starts the development server. Run these commands in the cloned repository directory. ```bash npm install npm run dev ``` -------------------------------- ### Example mysqldump command for example_db Source: https://stackrender.io/docs/import/mysql Example usage of the mysqldump command with a specific username, database name, and output file. It prompts for the database password and generates example_db.sql. ```bash mysqldump -u root -p --no-data example_db > example_db.sql ``` -------------------------------- ### Export PostgreSQL schema with pg_dump Source: https://stackrender.io/docs/import/postgresql Use the first command to export only the schema of a PostgreSQL database to a .sql file. The second command is a concrete example with root as the username, example_db as the database, and example_db.sql as the output file. Both commands must be run in a terminal after installing PostgreSQL tools. ```bash pg_dump -U [username] -d [database_name] --schema-only -f [output_file.sql] ``` ```bash pg_dump -U root -d example_db --schema-only -f example_db.sql ``` -------------------------------- ### Composite Primary Key SQL Example Source: https://stackrender.io/docs/diagram-editor/table-fields Shows the SQL output generated when multiple primary keys are defined, creating a composite primary key. The example uses employee_id and room_id as the composite key in the EmployeeRoomAssignment table. ```sql CREATE TABLE EmployeeRoomAssignment ( employee_id INT NOT NULL, room_id INT NOT NULL, assigned_date DATE, PRIMARY KEY (employee_id, room_id) ); ``` -------------------------------- ### Export SQLite schema with sqlite3 Source: https://stackrender.io/docs/import/sqlite Export a SQLite database schema to a .sql file using the sqlite3 command-line tool. The first command is the general form; the second is a concrete example. Requires sqlite3 to be installed. The generated .sql file can be pasted into StackRender's Import SQL section. ```bash sqlite3 [database_path] .schema > [output_file.sql] ``` ```bash sqlite3 example_db.db .schema > example_db.sql ``` -------------------------------- ### Export SQL from StackRender: Example Generated DDL Source: https://stackrender.io/docs/export Example SQL generated by StackRender when exporting a database diagram. It includes CREATE TABLE statements for products, payments, shipments, order_items, product_images, carts, reviews, cart_items, orders, vendor_payouts, users, categories, and vendors, along with CREATE TYPE statements for enums and a unique index. The SQL uses SERIAL primary keys, NUMERIC(10,2) for monetary values, and TIMESTAMPTZ defaults to CURRENT_TIMESTAMP. ```sql CREATE TABLE "products" ( id SERIAL NOT NULL PRIMARY KEY, vendor_id INTEGER NOT NULL, category_id INTEGER NULL, name TEXT NOT NULL, description TEXT NULL, price NUMERIC(10, 2) NOT NULL, stock_quantity INTEGER NOT NULL, sku TEXT NULL UNIQUE, created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE UNIQUE INDEX "products_name_index" ON "products" ("sku", "name"); CREATE TYPE "payments_payment_status_enum" AS ENUM('unpaid', 'paid', 'refunded'); CREATE TABLE "payments" ( id SERIAL NOT NULL PRIMARY KEY, order_id INTEGER NOT NULL UNIQUE, payment_date TIMESTAMPTZ NULL, amount NUMERIC(10, 2) NOT NULL, payment_method TEXT NULL, transaction_id TEXT NULL UNIQUE, payment_status payments_payment_status_enum NOT NULL DEFAULT 'unpaid', created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TYPE "shipments_fulfillment_status_enum" AS ENUM( 'not_fulfilled', 'fulfilled', 'partially_fulfilled' ); CREATE TABLE "shipments" ( id SERIAL NOT NULL PRIMARY KEY, order_id INTEGER NOT NULL UNIQUE, shipment_date TIMESTAMPTZ NULL, tracking_number TEXT NULL UNIQUE, carrier TEXT NULL, fulfillment_status shipments_fulfillment_status_enum NOT NULL DEFAULT 'not_fulfilled', created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE "order_items" ( id SERIAL NOT NULL PRIMARY KEY, order_id INTEGER NOT NULL, product_id INTEGER NOT NULL, vendor_id INTEGER NOT NULL, quantity INTEGER NOT NULL, price_per_item NUMERIC(10, 2) NOT NULL, subtotal NUMERIC(10, 2) NOT NULL ); CREATE TABLE "product_images" ( id SERIAL NOT NULL PRIMARY KEY, product_id INTEGER NOT NULL, image_url TEXT NOT NULL, alt_text TEXT NULL, display_order INTEGER NULL ); CREATE TABLE "carts" ( id SERIAL NOT NULL PRIMARY KEY, user_id INTEGER NOT NULL UNIQUE, created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE "reviews" ( id SERIAL NOT NULL PRIMARY KEY, product_id INTEGER NOT NULL, user_id INTEGER NOT NULL, rating INTEGER NOT NULL, comment TEXT NULL, review_date TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE "cart_items" ( id SERIAL NOT NULL PRIMARY KEY, cart_id INTEGER NOT NULL, product_id INTEGER NOT NULL, quantity INTEGER NOT NULL, added_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TYPE "orders_currency_enum" AS ENUM('USD', 'EUR', 'GBP'); CREATE TYPE "orders_order_status_enum" AS ENUM( 'pending', 'processing', 'shipped', 'delivered', 'cancelled' ); CREATE TABLE "orders" ( id SERIAL NOT NULL PRIMARY KEY, user_id INTEGER NOT NULL, order_date TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, total_amount NUMERIC(10, 2) NOT NULL, currency orders_currency_enum NOT NULL, order_status orders_order_status_enum NOT NULL DEFAULT 'pending', shipping_address TEXT NULL, billing_address TEXT NULL, created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE "vendor_payouts" ( id SERIAL NOT NULL PRIMARY KEY, vendor_id INTEGER NOT NULL, payout_date TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, amount NUMERIC(10, 2) NOT NULL, transaction_id TEXT NULL UNIQUE ); CREATE TABLE "users" ( id SERIAL NOT NULL PRIMARY KEY, username TEXT NOT NULL UNIQUE, email TEXT NOT NULL UNIQUE, password_hash TEXT NOT NULL, first_name TEXT NULL, last_name TEXT NULL, shipping_address TEXT NULL, billing_address TEXT NULL, created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE "categories" ( id SERIAL NOT NULL PRIMARY KEY, name TEXT NOT NULL UNIQUE, description TEXT NULL ); CREATE TABLE "vendors" ( id SERIAL NOT NULL PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, phone_number TEXT NULL, address TEXT NULL, created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ); ``` -------------------------------- ### DateTime: NOW() Function Source: https://stackrender.io/docs/diagram-editor/data-types Automatically sets the field to the current date and time when a record is created. Example: created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP. ```sql created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP ``` -------------------------------- ### DateTime: No Default Value Source: https://stackrender.io/docs/diagram-editor/data-types Leaves the field empty unless explicitly set. Example: due_date TIMESTAMP NOT NULL. ```sql due_date TIMESTAMP NOT NULL ``` -------------------------------- ### Export MariaDB schema with mariadb-dump Source: https://stackrender.io/docs/import/mariadb Export a MariaDB database schema without data using mariadb-dump. The first command shows the general syntax with placeholders; the second is a concrete example. Both prompt for the database password and produce a .sql file containing the schema. ```bash mariadb-dump -u [username] -p --no-data [database_name] > [output_file.sql] ``` ```bash mariadb-dump -u root -p --no-data example_db > example_db.sql ``` -------------------------------- ### SQL: Add foreign key constraint with ON DELETE CASCADE and ON UPDATE SET NULL Source: https://stackrender.io/docs/diagram-editor/relationships Example SQL output from StackRender for adding a foreign key constraint to the 'lists' table, referencing the 'users' table. It demonstrates the ON DELETE CASCADE and ON UPDATE SET NULL actions. ```sql ALTER TABLE "lists" ADD CONSTRAINT "fk_users_lists" FOREIGN KEY (user_id) REFERENCES "users" (id) ON DELETE CASCADE ON UPDATE SET NULL; ``` -------------------------------- ### Date: Custom Default Value Source: https://stackrender.io/docs/diagram-editor/data-types Stores calendar dates with a custom default value. Example: certification_date DATE NULL DEFAULT '1999-01-01'. ```sql certification_date DATE NULL DEFAULT '1999-01-01' ``` -------------------------------- ### TIME: Custom Default Value Source: https://stackrender.io/docs/diagram-editor/data-types Stores time values with a custom default value. Example: check_in TIME NULL DEFAULT '08:00:00'. ```sql check_in TIME NULL DEFAULT '08:00:00' ``` -------------------------------- ### DateTime: Custom Default Value Source: https://stackrender.io/docs/diagram-editor/data-types Specifies a fixed default value. Example: fixed_date TIMESTAMP NOT NULL DEFAULT '2026-03-11 03:08:25'. ```sql fixed_date TIMESTAMP NOT NULL DEFAULT '2026-03-11 03:08:25' ``` -------------------------------- ### SQL: Create junction table 'task_tags' for many-to-many relationship Source: https://stackrender.io/docs/diagram-editor/relationships Example SQL output from StackRender for a many-to-many relationship between 'tasks' and 'tags' tables. It creates the junction table 'task_tags' with a composite primary key and two foreign key constraints referencing the related tables. ```sql CREATE TABLE "task_tags" ( task_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, PRIMARY KEY ("task_id", "tag_id") ); ALTER TABLE "task_tags" ADD CONSTRAINT "fk_tasks_task_tags" FOREIGN KEY (task_id) REFERENCES "tasks" (id) ON DELETE CASCADE; ALTER TABLE "task_tags" ADD CONSTRAINT "fk_tags_task_tags" FOREIGN KEY (tag_id) REFERENCES "tags" (id) ON DELETE CASCADE; ``` -------------------------------- ### Year: Custom Default Value Source: https://stackrender.io/docs/diagram-editor/data-types Stores year values (MySQL/MariaDB) with a custom default value. Example: construction_year YEAR NULL DEFAULT '1999'. ```sql construction_year YEAR NULL DEFAULT '1999' ``` -------------------------------- ### Clone the StackRender repository Source: https://stackrender.io/docs/self-hosted Clones the StackRender project from GitHub to your local machine. This is the first step to self-hosting. ```bash git clone https://github.com/stackrender/stackrender.git ``` -------------------------------- ### Create unique index on products table Source: https://stackrender.io/docs/diagram-editor/indexes Generated by StackRender when a unique index is configured on the products table for the name and sku columns. Use this SQL to create the index in your database. ```sql CREATE UNIQUE INDEX "products_name_index" ON "products" ("name", "sku"); ``` -------------------------------- ### Export MySQL schema with mysqldump Source: https://stackrender.io/docs/import/mysql Run this command in your terminal to export only the database schema (without data) using mysqldump. It will prompt for your database password and generate a .sql file containing the schema. ```bash mysqldump -u [username] -p --no-data [database_name] > [output_file.sql] ``` -------------------------------- ### Generated SQL: Add Foreign Key Constraints Source: https://stackrender.io/docs/export This SQL script adds multiple foreign key constraints to enforce relationships between tables. It includes ON DELETE CASCADE for dependent child tables (e.g., shipments, order_items, reviews, cart_items, product_images, payments) and standard constraints for other references. Use this as a reference for the SQL export format from StackRender. ```sql ALTER TABLE "products" ADD CONSTRAINT "fk_vendors_products" FOREIGN KEY (vendor_id) REFERENCES "vendors" (id); ALTER TABLE "shipments" ADD CONSTRAINT "fk_orders_shipments" FOREIGN KEY (order_id) REFERENCES "orders" (id) ON DELETE CASCADE; ALTER TABLE "vendor_payouts" ADD CONSTRAINT "fk_vendors_vendor_payouts" FOREIGN KEY (vendor_id) REFERENCES "vendors" (id); ALTER TABLE "order_items" ADD CONSTRAINT "fk_orders_order_items" FOREIGN KEY (order_id) REFERENCES "orders" (id) ON DELETE CASCADE; ALTER TABLE "reviews" ADD CONSTRAINT "fk_products_reviews" FOREIGN KEY (product_id) REFERENCES "products" (id) ON DELETE CASCADE; ALTER TABLE "reviews" ADD CONSTRAINT "fk_users_reviews" FOREIGN KEY (user_id) REFERENCES "users" (id); ALTER TABLE "order_items" ADD CONSTRAINT "fk_products_order_items" FOREIGN KEY (product_id) REFERENCES "products" (id); ALTER TABLE "orders" ADD CONSTRAINT "fk_users_orders" FOREIGN KEY (user_id) REFERENCES "users" (id); ALTER TABLE "carts" ADD CONSTRAINT "fk_users_carts" FOREIGN KEY (user_id) REFERENCES "users" (id); ALTER TABLE "cart_items" ADD CONSTRAINT "fk_carts_cart_items" FOREIGN KEY (cart_id) REFERENCES "carts" (id) ON DELETE CASCADE; ALTER TABLE "product_images" ADD CONSTRAINT "fk_products_product_images" FOREIGN KEY (product_id) REFERENCES "products" (id) ON DELETE CASCADE; ALTER TABLE "cart_items" ADD CONSTRAINT "fk_products_cart_items" FOREIGN KEY (product_id) REFERENCES "products" (id); ALTER TABLE "order_items" ADD CONSTRAINT "fk_vendors_order_items" FOREIGN KEY (vendor_id) REFERENCES "vendors" (id); ALTER TABLE "products" ADD CONSTRAINT "fk_categories_products" FOREIGN KEY (category_id) REFERENCES "categories" (id); ALTER TABLE "payments" ADD CONSTRAINT "fk_orders_payments" FOREIGN KEY (order_id) REFERENCES "orders" (id) ON DELETE CASCADE; ``` -------------------------------- ### PostgreSQL ENUM type generation Source: https://stackrender.io/docs/diagram-editor/data-types Output from StackRender when creating an ENUM field: generates a named ENUM type using `table_column_enum` format and a table with the ENUM column. Requires entering enum values in the multi-value input and enabling type casting when changing data types. ```SQL CREATE TYPE "users_role_enum" AS ENUM('user', 'customer', 'admin', 'vendor'); CREATE TABLE "users" ( id SERIAL NOT NULL PRIMARY KEY, full_name VARCHAR NOT NULL, email VARCHAR(100) NOT NULL UNIQUE, picture_url VARCHAR NULL, phone_number VARCHAR NULL UNIQUE, password_hash VARCHAR NOT NULL, role users_role_enum NOT NULL DEFAULT 'user' ); ``` -------------------------------- ### PostgreSQL UUIDv4 default value Source: https://stackrender.io/docs/diagram-editor/data-types Generated SQL output when a UUID field is configured with the 'Random Value' default option, producing a `DEFAULT gen_random_uuid()` expression. ```SQL CREATE TABLE "users" ( id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, full_name VARCHAR NOT NULL ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.