Skip to content

Commit 38ac6ee

Browse files
committed
ai-assisted-sqlite-integration
1 parent fcced85 commit 38ac6ee

File tree

15 files changed

+1842
-65
lines changed

15 files changed

+1842
-65
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: shivammathur/setup-php@v2
2121
with:
2222
php-version: '8.3'
23+
extensions: pdo_sqlite
2324
tools: composer:v2
2425
coverage: none
2526

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ includes/cache/**
22
includes/vendor/**
33
includes/templates_c/**
44
includes/database_info.php
5+
includes/*.sqlite
56
composer.lock
67

78
.DS_Store

README.md

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
</p>
1313

14-
Live Demo: https://secretrepublic-v3.nenuadrian.com
15-
1614
Hosted on recommended provider [DreamHost](https://mbsy.co/dreamhost/92571715).
1715

1816
Audio Trailer: https://www.youtube.com/watch?v=6thfiGb-b7c
@@ -30,6 +28,7 @@ Audio Trailer: https://www.youtube.com/watch?v=6thfiGb-b7c
3028
- [Require steps](#require-steps)
3129
- [Semi-manual setup](#semi-manual-setup)
3230
- [Manual setup](#manual-setup)
31+
- [SQLite details](#sqlite-details)
3332
- [Useful tips](#useful-tips)
3433
- [Cron jobs](#cron-jobs)
3534
- [Screenshots](#screenshots)
@@ -106,7 +105,7 @@ https://github.com/nenuadrian/Secret-Republic-Hacker-Game-ORPBG-Alpha
106105
### Require steps
107106

108107
You need a webserver (e.g. MAMP/WAMP/XAMPP) able to run PHP (tested with 7.3) and a database.
109-
Both MySQL and local SQLite are supported.
108+
Both MySQL and local SQLite are supported. SQLite requires the `pdo_sqlite` PHP extension (enabled by default in most installations).
110109

111110
1. Install `composer` (the PHP dependency management system - `brew install composer` for MacOS if you have brew) and run `composer install`
112111

@@ -124,20 +123,57 @@ You can choose `MYSQL` or `SQLITE (LOCAL FILE)` on the setup screen.
124123

125124
### Manual setup
126125

127-
1. If you are using MySQL, import `includes/install/DB.sql` to the database you have created.
128-
129-
2. Rename `includes/database_info.php.template` to `includes/database_info.php` and update the details within accordingly:
130-
131-
- MySQL mode: set `$db['driver'] = 'mysql'` and fill host/user/password/name/port
132-
- SQLite mode: set `$db['driver'] = 'sqlite'` and set `$db['sqlite_path']` (for example `includes/local.sqlite`)
133-
134-
3. The game should be up and running. Go and create and account manually.
135-
136-
4. Go to the `user_credentials` table and update the entry for your user, setting the column `group_id` to be `1`. This will make your account a full administrator. Log out and log back in.
126+
1. Rename `includes/database_info.php.template` to `includes/database_info.php` and configure it:
127+
128+
**MySQL mode:**
129+
```php
130+
$db['driver'] = 'mysql';
131+
$db['server_name'] = 'localhost';
132+
$db['username'] = 'root';
133+
$db['password'] = '';
134+
$db['name'] = 'your_database';
135+
$db['port'] = 3306;
136+
```
137+
Then import the schema: `mysql -u root your_database < includes/install/DB.sql`
138+
139+
**SQLite mode:**
140+
```php
141+
$db['driver'] = 'sqlite';
142+
$db['sqlite_path'] = 'includes/local.sqlite';
143+
```
144+
The SQLite schema is imported automatically on first run via the setup page. For manual import, use the PHP helper:
145+
```php
146+
require_once 'includes/class/SqliteDb.php';
147+
require_once 'includes/class/SqliteSchemaConverter.php';
148+
$db = new SqliteDb('includes/local.sqlite');
149+
$stmts = SqliteSchemaConverter::convertMySqlDump(file_get_contents('includes/install/DB.sql'));
150+
foreach ($stmts as $sql) { $db->rawQuery($sql); }
151+
```
152+
153+
2. The game should be up and running. Go and create an account manually.
154+
155+
3. Go to the `user_credentials` table and update the entry for your user, setting the column `group_id` to be `1`. This will make your account a full administrator. Log out and log back in.
156+
157+
### SQLite details
158+
159+
SQLite support requires no external database server. The database is stored as a single file (default: `includes/local.sqlite`). The path can be relative to the project root or absolute.
160+
161+
**How it works:**
162+
- `SqliteSchemaConverter` automatically converts the MySQL schema (`DB.sql`) to SQLite-compatible SQL at setup time, handling type mappings, escape sequences, primary keys and auto-increment columns.
163+
- `SqliteDb` is a lightweight PDO-based adapter that mirrors the `Mysqlidb` API (query builder, `where()`, `join()`, `get()`, `insert()`, `update()`, `delete()`, `rawQuery()`, etc.) so the game code works with either driver.
164+
- MySQL-specific SQL like `RAND()` is translated to `RANDOM()` at runtime, and `UPDATE/DELETE ... LIMIT` is rewritten using subqueries.
165+
166+
**Requirements:**
167+
- PHP `pdo_sqlite` extension (included by default in most PHP installations)
168+
- Write permission on the directory where the `.sqlite` file will be created
169+
170+
**Limitations:**
171+
- SQLite is best for development and small deployments. For production with many concurrent users, MySQL is recommended.
172+
- Foreign key constraints from the MySQL schema are partially supported (inline constraints work; ALTER TABLE constraints are skipped as SQLite has limited ALTER TABLE support).
137173

138174
### Useful tips
139175

140-
You may need to manually execute the following SQL if you see a GROUP BY related error on the missions page:
176+
You may need to manually execute the following SQL if you see a GROUP BY related error on the missions page (MySQL only):
141177

142178
```
143179
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

docs/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Secret Republic V3 Documentation
22

3-
This documentation is generated from project sources, with material extracted from `README.md`, `includes/`, and `tests/`.
3+
This documentation is generated from project sources, with material extracted from , , and .
44

55
## Repository Snapshot
66

@@ -12,10 +12,12 @@ This documentation is generated from project sources, with material extracted fr
1212
## What Is Included
1313

1414
- README-based project documentation and setup notes
15-
- Routing and request lifecycle notes from `public_html/index.php`
15+
- Routing and request lifecycle notes from
1616
- Auto-generated module/class/constants/test inventories
1717

1818
## Next Steps
1919

2020
- Use the navigation sidebar to explore generated references.
21+
- Update code and rerun .
22+
lore generated references.
2123
- Update code and rerun `./scripts/generate-mkdocs-material.sh`.

docs/project/readme.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,30 @@ https://github.com/nenuadrian/Secret-Republic-Hacker-Game-ORPBG-Alpha
8484

8585
## Require steps
8686

87-
You need a webserver (e.g. MAMP/WAMP/XAMPP) able to run PHP (tested with 7.3) and an MySQL database (LAMP stack).
87+
You need a webserver (e.g. MAMP/WAMP/XAMPP) able to run PHP (tested with 7.3) and a database.
88+
Both MySQL and local SQLite are supported.
8889

8990
1. Install `composer` (the PHP dependency management system - `brew install composer` for MacOS if you have brew) and run `composer install`
9091

91-
2. Create an empty Database in MySQL. For MAMP, you would go to `http://localhost:8888/phpMyAdmin5`
92+
2. Pick one database mode:
93+
94+
- MySQL: create an empty database (for MAMP you can use `http://localhost:8888/phpMyAdmin5`)
95+
- SQLite (local): no external DB server needed; setup creates a local `.sqlite` file
9296

9397
## Semi-manual setup
9498

9599

96-
Visit `http://localhost/public_html/setup` - this may be different if you are using another port or directory structure, e.g. `http://localhost:8888/sr/public_html/setup` and follow the setup process
100+
Visit `http://localhost/public_html/setup` - this may be different if you are using another port or directory structure, e.g. `http://localhost:8888/sr/public_html/setup` and follow the setup process.
101+
You can choose `MYSQL` or `SQLITE (LOCAL FILE)` on the setup screen.
97102

98103
## Manual setup
99104

100-
1. Import `includes/install/DB.sql` to the database you have created.
105+
1. If you are using MySQL, import `includes/install/DB.sql` to the database you have created.
106+
107+
2. Rename `includes/database_info.php.template` to `includes/database_info.php` and update the details within accordingly:
101108

102-
2. Rename `includes/database_info.php.template` to `includes/database_info.php` and update the details within accordingly.
109+
- MySQL mode: set `$db['driver'] = 'mysql'` and fill host/user/password/name/port
110+
- SQLite mode: set `$db['driver'] = 'sqlite'` and set `$db['sqlite_path']` (for example `includes/local.sqlite`)
103111

104112
3. The game should be up and running. Go and create and account manually.
105113

docs/project/setup.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ The canonical setup instructions live in `README.md` under **Simple-Setup** and
44

55
## Fast Path
66

7-
1. Install PHP + Composer + MySQL.
7+
1. Install PHP + Composer + a database (MySQL or local SQLite).
88
2. Run `composer install`.
9-
3. Create a MySQL database.
10-
4. Finish setup via `/public_html/setup` or manual SQL import + config file.
9+
3. If using MySQL, create a MySQL database.
10+
4. Finish setup via `/public_html/setup` (choose `MYSQL` or `SQLITE (LOCAL FILE)`) or manual SQL import + config file.
1111

1212
## Manual Essentials
1313

14-
- Import `includes/install/DB.sql`.
15-
- Create `includes/database_info.php` from `includes/database_info.php.template`.
14+
- Import `includes/install/DB.sql` (MySQL mode).
15+
- Create `includes/database_info.php` from `includes/database_info.php.template` and set:
16+
- `driver = 'mysql'` with host/user/password/name/port, or
17+
- `driver = 'sqlite'` with `sqlite_path`.
1618
- Promote your first user to admin (`user_credentials.group_id = 1`).
1719

1820
## Cron Endpoints

0 commit comments

Comments
 (0)