Skip to content

Field Descriptions

This document provides detailed descriptions and usage examples of database fields.

General Field Descriptions

Timestamp Fields

All tables include the following timestamp fields:

Field NameTypeDefault ValueDescription
created_atTIMESTAMPCURRENT_TIMESTAMPRecord creation time
updated_atTIMESTAMPAuto-updateRecord update time

Status Fields

Different types of status fields:

Table NameField NamePossible Values
usersstatusactive, inactive
articlesstatusdraft, published
projectsstatusdraft, published
categoriesstatusactive, inactive
galleriesstatusdraft, published
wall_messagesstatuspending, approved, rejected
skillsstatusactive, inactive

Table Field Details

users (User Table)

role Field

ValueDescriptionPermissions
adminAdministratorFull backend management permissions
userRegular userBasic access permissions

password Field

  • Uses bcrypt encryption
  • Storage format: $2b$10$... (60 characters)
  • Encryption strength: 10 rounds

Example:

sql
-- Original password: 123456
-- Encrypted: $2b$10$lhcSe2CnCAETOw5wcXpFwu8vMydw8h8BPIqOyGnNeIAgvDO3f9VmW

articles (Article Table)

status Field

ValueDescriptionVisible
draftDraftNo
publishedPublishedYes
  • Type: TINYINT(1)
  • Values: 0 (not featured), 1 (featured)
  • Used for featured article display on homepage

technologies Field (projects table)

  • Type: JSON
  • Storage format: Array string
  • Example: ["Vue.js", "Node.js", "TypeScript"]

SQL Example:

sql
INSERT INTO projects (title, technologies) 
VALUES ('My Project', '["Vue.js", "Node.js"]');

Query Example:

sql
-- Find projects containing specific technologies
SELECT * FROM projects 
WHERE JSON_CONTAINS(technologies, '"Vue.js"');

settings (System Settings Table)

group_name Field

GroupPurpose
statsStatistical data (total visits, today's visits, etc.)
storage_settingsStorage settings (local, S3, MinIO, etc.)
analyticsAnalytics tracking codes (Google Analytics, etc.)
technologiesTechnology tag list

Example Data:

sql
-- Statistical data
INSERT INTO settings (group_name, key_name, key_value)
VALUES 
('stats', 'total_visits', '1000'),
('stats', 'today_visits', '50');

-- Storage settings
INSERT INTO settings (group_name, key_name, key_value)
VALUES 
('storage_settings', 'storage_type', 'local'),
('storage_settings', 'uploadPath', './uploads');

-- Technology tags (JSON format)
INSERT INTO settings (group_name, key_name, key_value)
VALUES
('technologies', 'list', '[{"id": 1, "name": "Vue.js", "icon": "lucide:code-2", "color": "#4fc08d"}]');

files (File Table)

storage_type Field

ValueDescription
localLocal file system
s3AWS S3 or compatible services (MinIO, Alibaba Cloud OSS, etc.)
qiniuQiniu Cloud Storage

category Field

Common file categories:

CategoryPurpose
coverCover images
avatarUser avatars
galleryGallery images
resourceResource files
carouselCarousel images

file_hash Field

  • Type: VARCHAR(64)
  • Format: SHA-256 hash value (64 hexadecimal characters)
  • Purpose: File deduplication and integrity verification

Generation Example:

javascript
import crypto from 'crypto'

const hash = crypto
  .createHash('sha256')
  .update(fileBuffer)
  .digest('hex')

skills (Skills Table)

level Field

ValueDescriptionProficiency Level
beginnerBeginnerJust started
intermediateIntermediateSome experience
advancedAdvancedProficient
expertExpertMastery

wall_messages (Wall Messages Table)

status Field

ValueDescriptionDisplayed
pendingPending reviewNo
approvedApprovedYes
rejectedRejectedNo

Index Explanation

Single-Column Index

sql
-- Create index on username field
INDEX idx_username (username)

-- Query will use index
SELECT * FROM users WHERE username = 'admin';

Unique Index

sql
-- Unique index on email field
UNIQUE KEY unique_email (email)

-- Prevent duplicate emails
INSERT INTO users (email) VALUES ('test@example.com');
-- Second insert will fail

Composite Index

sql
-- Composite index on date and hour
UNIQUE KEY unique_date_hour (date, hour)

-- Query will use index
SELECT * FROM visit_hourly_statistics 
WHERE date = '2025-01-24' AND hour = 10;

Full-text Index

sql
-- Full-text index on title and description
FULLTEXT KEY idx_title_desc (title, description)

-- Full-text search
SELECT * FROM articles 
WHERE MATCH(title, description) AGAINST('Nuxt 4' IN NATURAL LANGUAGE MODE);

Foreign Key Constraints

Foreign Key Types

sql
-- CASCADE: Automatically delete child records when parent is deleted
FOREIGN KEY (gallery_id) REFERENCES galleries(id) ON DELETE CASCADE

-- SET NULL: Set foreign key to NULL when parent is deleted
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL

-- RESTRICT: Prevent deletion of parent record
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE RESTRICT

Usage Examples

sql
-- When deleting a gallery, automatically delete associated images
DELETE FROM galleries WHERE id = 1;

-- When deleting a user, set author_id to NULL in articles
DELETE FROM users WHERE id = 1;

-- If a file is used by resources, prevent deletion
DELETE FROM files WHERE id = 1; -- Will fail if referenced

Data Type Explanations

VARCHAR vs TEXT

TypeMax LengthPurpose
VARCHAR(255)255 charactersShort text (usernames, emails, etc.)
TEXT65,535 charactersMedium-length text (introductions, descriptions)
LONGTEXT4,294,967,295 charactersLong text (article content)

INT vs BIGINT

TypeRangePurpose
INT-2^31 ~ 2^31-1Regular quantities (views, likes)
BIGINT-2^63 ~ 2^63-1Large numbers (file sizes)

TIMESTAMP vs DATETIME

TypeRangeTimezone
TIMESTAMP1970-2038UTC
DATETIME1000-9999Server timezone

Character Set and Collation

sql
-- Database character set
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci
  • utf8mb4: Supports full Unicode (including emoji)
  • utf8mb4_unicode_ci: Case-insensitive collation

Notes

  1. Foreign Key Constraints: Pay attention to dependencies when deleting data
  2. Time Format: Use ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ)
  3. JSON Fields: Use MySQL 5.7+ JSON functions for operations
  4. Index Optimization: Frequently queried fields should have indexes
  5. Character Set: Always use utf8mb4 to support multiple languages