- Primary Key
- Audit Timestamps
- User Tracking
- Soft Delete
Schema Overview
The Muebles Roble database schema is designed to support a furniture management system with catalogs for colors, wood types, roles, units of measure, and furniture types.Current Tables
colors
5 records - Color catalog for furniture
roles
User roles for access control
wood_types
Wood material classifications
unit_of_measures
Measurement units (cm, m, kg, etc.)
furniture_type
Furniture category classifications
Table Schemas
colors
Stores color catalog entries for furniture references.| Column | Type | Constraints | Description |
|---|---|---|---|
id_color | INTEGER | PRIMARY KEY | Unique identifier |
name | VARCHAR(50) | NOT NULL, UNIQUE | Color name |
active | BOOLEAN | NOT NULL, DEFAULT TRUE | Active status |
created_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP | Creation timestamp |
updated_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | Last update timestamp |
deleted_at | TIMESTAMP | NULL | Soft delete timestamp |
created_by | VARCHAR(100) | NULL | User who created record |
updated_by | VARCHAR(100) | NULL | User who updated record |
deleted_by | VARCHAR(100) | NULL | User who deleted record |
- PRIMARY KEY on
id_color - UNIQUE INDEX on
name
roles
Manages user roles for permissions and access control.| Column | Type | Constraints | Description |
|---|---|---|---|
id_role | INTEGER | PRIMARY KEY | Unique identifier |
name | VARCHAR(50) | NOT NULL, UNIQUE | Role name (e.g., ‘Admin’, ‘Editor’) |
active | BOOLEAN | NOT NULL, DEFAULT TRUE | Active status |
created_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP | Creation timestamp |
updated_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | Last update timestamp |
deleted_at | TIMESTAMP | NULL | Soft delete timestamp |
created_by | VARCHAR(100) | NULL | User who created record |
updated_by | VARCHAR(100) | NULL | User who updated record |
deleted_by | VARCHAR(100) | NULL | User who deleted record |
- PRIMARY KEY on
id_role - UNIQUE INDEX on
name
wood_types
Catalogs different types of wood materials.| Column | Type | Constraints | Description |
|---|---|---|---|
id_wood_type | INTEGER | PRIMARY KEY | Unique identifier |
name | VARCHAR(100) | NOT NULL, UNIQUE | Wood type name |
description | VARCHAR(255) | NULL | Optional description |
active | BOOLEAN | NOT NULL, DEFAULT TRUE | Active status |
created_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP | Creation timestamp |
updated_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | Last update timestamp |
deleted_at | TIMESTAMP | NULL | Soft delete timestamp |
created_by | VARCHAR(100) | NULL | User who created record |
updated_by | VARCHAR(100) | NULL | User who updated record |
deleted_by | VARCHAR(100) | NULL | User who deleted record |
- PRIMARY KEY on
id_wood_type - UNIQUE INDEX on
name
unit_of_measures
Manages measurement units for inventory and specifications.| Column | Type | Constraints | Description |
|---|---|---|---|
id_unit_of_measure | INTEGER | PRIMARY KEY | Unique identifier |
name | VARCHAR(50) | NOT NULL, UNIQUE | Unit name (e.g., “Centimeter”) |
abbreviation | VARCHAR(10) | NOT NULL, UNIQUE | Unit abbreviation (e.g., “cm”) |
active | BOOLEAN | NOT NULL, DEFAULT TRUE | Active status |
created_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP | Creation timestamp |
updated_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | Last update timestamp |
deleted_at | TIMESTAMP | NULL | Soft delete timestamp |
created_by | VARCHAR(100) | NULL | User who created record |
updated_by | VARCHAR(100) | NULL | User who updated record |
deleted_by | VARCHAR(100) | NULL | User who deleted record |
- PRIMARY KEY on
id_unit_of_measure - UNIQUE INDEX on
name - UNIQUE INDEX on
abbreviation
furniture_type
Classifies different types of furniture.| Column | Type | Constraints | Description |
|---|---|---|---|
id_furniture_type | INTEGER | PRIMARY KEY | Unique identifier |
name | VARCHAR(50) | NOT NULL, UNIQUE | Furniture type name |
active | BOOLEAN | NOT NULL, DEFAULT TRUE | Active status |
created_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP | Creation timestamp |
updated_at | TIMESTAMP | NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | Last update timestamp |
deleted_at | TIMESTAMP | NULL | Soft delete timestamp |
created_by | VARCHAR(100) | NULL | User who created record |
updated_by | VARCHAR(100) | NULL | User who updated record |
deleted_by | VARCHAR(100) | NULL | User who deleted record |
- PRIMARY KEY on
id_furniture_type - UNIQUE INDEX on
name
Common Schema Patterns
Standard Field Structure
All tables follow a consistent field pattern:Naming Conventions
Table Names
Table Names
- Use plural form:
colors,roles,wood_types - Use snake_case:
unit_of_measures, notUnitOfMeasures - Be descriptive and specific
Column Names
Column Names
- Use snake_case:
id_color,created_at - Primary keys:
id_{table_name}(e.g.,id_color) - Foreign keys:
id_{referenced_table}(e.g.,id_colorin furniture table) - Booleans: Use affirmative names (
active, notinactive)
Constraint Names
Constraint Names
- Primary keys:
pk_{table_name} - Foreign keys:
fk_{table}_{referenced_table} - Unique constraints:
uq_{table}_{column} - Indexes:
idx_{table}_{column}
Data Types
String Fields
Numeric Fields
Date/Time Fields
Boolean Fields
Schema Evolution
Adding New Tables
When adding a new table, follow this template:Adding Relationships
When adding foreign keys:Database Configuration
Connection Settings
Database configuration is managed through environment variables:config.py
Environment Variables
.env
Query Performance
Recommended Indexes
All tables have these indexes by default:Query Optimization
- Filter Active Records
- Case-Insensitive Search
- Count Efficiently
Always filter by
active status:Schema Maintenance
Regular Tasks
Next Steps
Database Models
Learn about ORM model definitions
Migrations
Understand the migration system