Overview
This page provides in-depth documentation for each model in the BD Scan Face database. Each model is designed to support specific aspects of the facial recognition access control system.All models use auto-incrementing integer primary keys and include appropriate foreign key relationships for data integrity.
Model Reference
UserType Model
UserType Model
Purpose
TheUserType model defines different categories of users in the system, such as administrators, employees, visitors, or contractors. This allows for role-based access control and different permission levels.Schema Definition
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
user_type_id | Int | Primary Key, Auto-increment | Unique identifier for the user type |
type_name | String | Unique, Max 50 chars | Name of the user type (e.g., “Administrator”, “Employee”) |
Relationships
- users: One-to-many relationship with the
Usermodel. A user type can be assigned to multiple users.
Database Mapping
Maps to theuser_types table in PostgreSQL.Usage Example
Constraints
- The
type_namefield must be unique across all user types - Cannot be deleted if users are still assigned to this type (foreign key constraint)
User Model
User Model
Purpose
TheUser model represents individuals who are authorized to access facilities. It stores personal information, authentication credentials, and links to facial recognition data.Schema Definition
Fields
| Field | Type | Constraints | Default | Description |
|---|---|---|---|---|
user_id | Int | Primary Key, Auto-increment | - | Unique identifier for the user |
ci | String | Unique, Max 20 chars | - | Identification document number (e.g., national ID, passport) |
first_name | String | Max 100 chars | - | User’s first name |
last_name | String | Max 100 chars | - | User’s last name |
email | String | Unique, Max 100 chars | - | User’s email address |
phone | String? | Optional, Max 20 chars | null | User’s phone number |
user_type_id | Int | Foreign Key | - | Reference to the user’s type |
code | Int | Unique | - | Numeric code for manual access entry |
status | Boolean | - | true | Whether the user is active in the system |
registration_date | DateTime | - | now() | Timestamp when the user was registered |
Relationships
- user_type: Many-to-one relationship with
UserType. Each user belongs to one user type. - faces: One-to-many relationship with
Face. A user can have multiple facial encodings registered. - access_logs: One-to-many relationship with
AccessLog. Tracks all access attempts by this user.
Database Mapping
Maps to theusers table in PostgreSQL.Usage Example
Constraints
ci,email, andcodemust be unique across all usersuser_type_idmust reference a valid user type- Cannot be deleted if facial encodings or access logs exist (foreign key constraint)
Face Model
Face Model
Purpose
TheFace model stores facial recognition encodings for users. Multiple face encodings can be registered for a single user to improve recognition accuracy across different angles and lighting conditions.Schema Definition
Fields
| Field | Type | Constraints | Default | Description |
|---|---|---|---|---|
face_id | Int | Primary Key, Auto-increment | - | Unique identifier for the face encoding |
user_id | Int | Foreign Key | - | Reference to the user this face belongs to |
encoding | String | Text | - | Base64-encoded facial recognition vector data |
image_path | String? | Optional, Text | null | Path to the original face image file |
upload_date | DateTime | - | now() | Timestamp when the face was registered |
Relationships
- user: Many-to-one relationship with
User. Each face encoding belongs to one user.
Database Mapping
Maps to thefaces table in PostgreSQL.Usage Example
Constraints
user_idmust reference a valid user- Cannot be created for a deleted user (foreign key constraint)
The encoding field stores the facial recognition vector as a string. The actual format depends on the face recognition library being used (e.g., face-api.js, OpenCV).
Best Practices
- Multiple Encodings: Register 2-3 face encodings per user from different angles for better recognition accuracy
- Image Storage: Store the original image in
image_pathfor audit purposes and potential re-encoding - Encoding Format: Use consistent encoding format across all face records
- Regular Updates: Consider updating face encodings periodically as appearance changes
Device Model
Device Model
Purpose
TheDevice model represents physical access control hardware such as cameras, facial recognition scanners, or access terminals deployed throughout facilities.Schema Definition
Fields
| Field | Type | Constraints | Default | Description |
|---|---|---|---|---|
device_id | Int | Primary Key, Auto-increment | - | Unique identifier for the device |
name | String | Max 100 chars | - | Descriptive name for the device |
location | String? | Optional, Max 100 chars | null | Physical location of the device |
ip_address | String? | Optional, Max 50 chars | null | IP address for network-connected devices |
status | Boolean | - | true | Whether the device is active and operational |
registration_date | DateTime | - | now() | Timestamp when the device was registered |
Relationships
- access_logs: One-to-many relationship with
AccessLog. Tracks all access attempts recorded by this device.
Database Mapping
Maps to thedevices table in PostgreSQL.Usage Example
Constraints
- Cannot be deleted if access logs exist for this device (foreign key constraint)
Device Status Management
Thestatus field indicates whether a device is:- Active (true): Currently operational and recording access attempts
- Inactive (false): Disabled, under maintenance, or decommissioned
AccessLog Model
AccessLog Model
Purpose
TheAccessLog model records all access attempts in the system, whether successful or failed. It provides a complete audit trail of facility access and facial recognition performance.Schema Definition
Fields
| Field | Type | Constraints | Default | Description |
|---|---|---|---|---|
log_id | Int | Primary Key, Auto-increment | - | Unique identifier for the access log entry |
user_id | Int? | Optional, Foreign Key | null | Reference to the user (null for unrecognized attempts) |
device_id | Int | Foreign Key | - | Reference to the device that recorded the access |
access_date | DateTime | - | now() | Timestamp of the access attempt |
confidence | Decimal(5,2) | Precision 5, Scale 2 | - | Recognition confidence score (0.00 to 100.00) |
access_type | String? | Optional, Max 20 chars | null | Type of access (e.g., “entry”, “exit”) |
status | String? | Optional, Max 20 chars | null | Status of the attempt (e.g., “granted”, “denied”) |
enterCode | Boolean | - | false | Whether manual code entry was used instead of face recognition |
Relationships
- user: Many-to-one relationship with
User(optional). Links to the recognized user, or null if unrecognized. - device: Many-to-one relationship with
Device. Identifies which device recorded the access.
Database Mapping
Maps to theaccess_logs table in PostgreSQL.Usage Example
Constraints
device_idmust reference a valid deviceuser_id(when not null) must reference a valid user- If the referenced user is deleted,
user_idis set to NULL to preserve the log
Field Details
Confidence Score
Theconfidence field represents the facial recognition algorithm’s confidence level:- 90-100: High confidence, very likely a match
- 70-89: Medium confidence, probable match
- 50-69: Low confidence, uncertain match
- 0-49: Very low confidence, likely not a match
Access Type
Common values foraccess_type:"entry": User entering a facility"exit": User exiting a facilitynull: Type not specified
Status
Common values forstatus:"granted": Access was allowed"denied": Access was refused"pending": Access requires manual approvalnull: Status not specified
Enter Code Flag
TheenterCode boolean indicates:true: User entered their numeric code manually (no facial recognition used)false: Facial recognition was used
The nullable
user_id field is critical for logging unrecognized access attempts. This helps identify potential security issues and improve the facial recognition system.Analytics Use Cases
Common Queries
User Management
Access Reporting
Next Steps
Schema Overview
View the complete database schema and relationships
Migrations
Learn how to manage database migrations