Schema Design
Creating an effective database schema is crucial for your application’s performance and scalability. CodeNull’s visual Schema Designer makes it easy to create, visualize, and optimize your database structure without writing complex code.Schema Designer Overview
The Schema Designer provides a visual interface for defining your data models and their relationships:
- Canvas: Visual workspace for arranging and connecting models
- Model Editor: Define fields, types, and validation rules
- Relationship Manager: Create connections between models
- Properties Panel: Configure detailed settings for selected elements
- Tool Palette: Access common schema design tools
Creating Data Models
1
Add a New Model
Click the “Add Model” button in the tool palette or right-click on the canvas and select “New Model”.
2
Define Basic Information
Enter the model’s name and description. For MongoDB, this will be a collection; for SQL databases, a table.

3
Add Fields
Click “Add Field” to add properties to your model. For each field, specify:
- Field name
- Data type
- Required status
- Default value
- Description
- Validation rules
4
Configure Advanced Settings
Set additional model properties:
- Indexes for query optimization
- Unique constraints
- Timestamps (created/updated)
- Soft delete options
- Access control rules
Defining Relationships
CodeNull makes it easy to create relationships between your data models:1
Start Relationship Creation
Click the “Create Relationship” tool in the palette, then click on the source model.
2
Select Relationship Type
Choose the type of relationship:
- One-to-One
- One-to-Many
- Many-to-Many
3
Connect to Target Model
Click on the target model to complete the connection.
4
Configure Relationship Details
Set properties for the relationship:
- Foreign key field names
- Cascade behavior (on update/delete)
- Relationship constraints
- Indexing options

Relationship Types Explained
One-to-One Relationships
One-to-One Relationships
Each record in Model A relates to exactly one record in Model B.Example: A User has one ProfileImplementation options:
- Reference field in either model
- Embedding in MongoDB
- Use when the related data is accessed together
- Consider embedding in MongoDB for better read performance
One-to-Many Relationships
One-to-Many Relationships
Each record in Model A relates to multiple records in Model B.Example: An Author has many BooksImplementation options:
- Reference field in the “many” side
- Array of references in the “one” side (MongoDB)
- Use reference in the “many” side for most cases
- Consider array of references only for small collections
Many-to-Many Relationships
Many-to-Many Relationships
Records in Model A can relate to multiple records in Model B, and vice versa.Example: Students and CoursesImplementation options:
- Junction/join table (SQL)
- Array of references on both sides (MongoDB)
- Separate collection for the relationship (MongoDB)
- Use junction table for SQL databases
- For MongoDB, use separate collection for relationships with metadata
Schema Optimization
CodeNull provides tools to optimize your database schema for performance:Indexing Strategy

- Single Field Indexes: Speed up queries on one field
- Compound Indexes: Optimize queries that filter or sort on multiple fields
- Text Indexes: Enable text search capabilities
- Unique Indexes: Enforce uniqueness constraints
- TTL Indexes: Automatically remove documents after a specified time
Schema Validation
Ensure data integrity with comprehensive validation rules:
- Required Fields: Ensure certain fields must have values
- Data Type Validation: Enforce correct data types
- Value Ranges: Set min/max values for numbers
- String Patterns: Apply regex patterns for strings
- Custom Validation: Create complex validation rules with JavaScript functions
Best Practices
When creating relationships, design your schema based on how the data will be accessed rather than just how it’s logically structured.
- Use descriptive names: Choose clear, consistent names for models and fields
- Document your schema: Add descriptions to models and fields to maintain clarity
- Plan for queries: Design your schema with your most common queries in mind
- Be cautious with array fields: Limit array sizes in MongoDB to avoid performance issues
- Use appropriate data types: Choose the most specific type for each field
- Consider read/write ratio: Optimize for reads in read-heavy applications