This repository contains the database schema and database management scripts for the Domain Monitoring System.
The Domain Monitoring System uses PostgreSQL as its primary database to store:
- User accounts and authentication information
- Domain monitoring configurations
- Domain scan results
domain-monitor-db/
├── schema/
│ └── schema.sql # Main database schema definition
├── scripts/
│ ├── backup.sh # Database backup script
│ └── restore.sh # Database restore script
├── .gitignore
└── README.md # This file
- PostgreSQL 12.0 or higher
- psql command-line client installed
- Linux/Mac OS X/Windows
- 1GB RAM minimum for database server
- 10GB disk space recommended for data and logs
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo yum install -y postgresql-server postgresql-contrib
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo systemctl enable postgresql
brew install postgresql
brew services start postgresql
-
Log into PostgreSQL as the postgres user:
sudo -u postgres psql
-
Create a database and user:
CREATE DATABASE monidb; CREATE USER moniuser WITH ENCRYPTED PASSWORD 'your_secure_password'; GRANT ALL PRIVILEGES ON DATABASE monidb TO moniuser;
-
Connect to the new database:
\c monidb
-
Apply the schema to your PostgreSQL database:
psql -U moniuser -d monidb -a -f schema/schema.sql
-
Verify the installation:
psql -U moniuser -d monidb -c "\dt"
You should see the tables defined in the schema.
Stores user account information:
user_id
: Unique identifier (primary key)username
: Username for login (email address)password
: User password (should be encrypted in production)full_name
: User's full name (optional)is_google_user
: Boolean flag for Google authenticationprofile_picture
: URL to user profile picture (for Google users)created_at
: Timestamp of account creation
Stores domain monitoring scan results:
scan_id
: Unique identifier for each scan (primary key)user_id
: Reference to the user who owns this domainurl
: Domain URL being monitoredstatus_code
: HTTP status result (OK/FAILED)ssl_status
: SSL certificate status (valid/failed)expiration_date
: SSL certificate expiration dateissuer
: SSL certificate issuer namelast_scan_time
: Timestamp of the last scan
In future versions, consider adding:
For storing scheduled monitoring tasks:
task_id
: Unique identifier for each taskuser_id
: Reference to the task ownertype
: Task type (hourly, daily)interval
: For hourly tasks - interval in hourstime
: For daily tasks - time to runnext_run
: Next scheduled execution timejob_id
: Reference to the scheduler job
To backup the database:
cd scripts
./backup.sh [optional_backup_directory]
This creates both SQL and binary format backups with timestamps.
To restore from a backup:
cd scripts
./restore.sh path/to/backup_file
This database is designed to work with:
- The backend service located in the domain-monitor-backend repository
- The deployment configuration in the domain-monitor-deploy repository
The application connects to this database using the following environment variables:
DB_NAME
: Database name (default: monidb)DB_USER
: Database username (default: moniuser)DB_PASSWORD
: Database user passwordDB_HOST
: Database host (default: localhost)DB_PORT
: Database port (default: 5432)
- Table names: lowercase, plural form (e.g.,
users
,scans
) - Column names: lowercase, snake_case (e.g.,
user_id
,last_scan_time
) - Primary keys: table name in singular form +
_id
(e.g.,user_id
,scan_id
) - Foreign keys: referenced table in singular form +
_id
(e.g.,user_id
) - Indexes:
idx_
+ table name +_
+ column name(s)
psql: error: could not connect to server: Connection refused
- Check if PostgreSQL is running:
sudo systemctl status postgresql
- Verify PostgreSQL is listening on the expected port:
sudo netstat -plunt | grep postgres
psql: error: FATAL: password authentication failed for user "moniuser"
- Verify the correct password is being used
- Check pg_hba.conf for proper authentication method
ERROR: permission denied for table users
- Verify the user has appropriate privileges:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO moniuser;
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature
- Commit your changes:
git commit -am 'Add my feature'
- Push to the branch:
git push origin feature/my-feature
- Submit a pull request