From ff9b85679bda4c7df6be9de4fd1de110641c0718 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 25 Feb 2024 23:32:07 +0100 Subject: [PATCH 01/13] use boolean for done --- src/templates/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/schema.sql b/src/templates/schema.sql index 7d8c81a..3e7beb5 100644 --- a/src/templates/schema.sql +++ b/src/templates/schema.sql @@ -7,5 +7,5 @@ CREATE TABLE IF NOT EXISTS `users` ( CREATE TABLE IF NOT EXISTS `tasks` ( `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, - `done` INTEGER(1) NOT NULL DEFAULT 0 + `done` TINYINT(1) NOT NULL DEFAULT 0 ); \ No newline at end of file From 6de9bd3178bc94f165528a45a2230bee5ae380c6 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 25 Feb 2024 23:32:20 +0100 Subject: [PATCH 02/13] 1.8.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c2d048a..e5105e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.8.1", + "version": "1.8.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.8.1", + "version": "1.8.2", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 4be18f9..2b3ac81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.8.1", + "version": "1.8.2", "description": "", "main": "src/index.js", "bin": "src/index.js", From c1c9c651bf33b47d497b8aab0de1cd35d251a01f Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Mon, 26 Feb 2024 00:40:02 +0100 Subject: [PATCH 03/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 106f917..8f0cc66 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](https://mariadb.org/), [phpMyAdmin](https://www.phpmyadmin.net/) and [PHP CRUD API](https://github.com/mevdschee/php-crud-api) to your local development environment. -You might be interested in a simple [JavaScript API Wrapper](https://github.com/scriptPilot/js-php-mysql-crud-api) or a [Local Persistent Database + MySQL Sync](https://github.com/scriptPilot/pouchdb-mysql/). +You might be interested in a simple [Synchronization between local IndexedDB and MySQL Database](https://github.com/scriptPilot/dexie-mysql-sync). ## Installation From 87c0e45bc98141bc08c9622529e0719dd6e2a896 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Tue, 27 Feb 2024 23:12:08 +0100 Subject: [PATCH 04/13] change default charset to utf8mb4 closes #8 --- src/templates/schema.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/schema.sql b/src/templates/schema.sql index 3e7beb5..46c62fb 100644 --- a/src/templates/schema.sql +++ b/src/templates/schema.sql @@ -2,10 +2,10 @@ CREATE TABLE IF NOT EXISTS `users` ( `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, `username` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL -); +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE IF NOT EXISTS `tasks` ( `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, `done` TINYINT(1) NOT NULL DEFAULT 0 -); \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; \ No newline at end of file From 41391939877d3940b38a912afd178afc55a7cd37 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Tue, 27 Feb 2024 23:12:19 +0100 Subject: [PATCH 05/13] 1.8.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e5105e0..8b2e14f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.8.2", + "version": "1.8.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.8.2", + "version": "1.8.3", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 2b3ac81..ed66ae0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.8.2", + "version": "1.8.3", "description": "", "main": "src/index.js", "bin": "src/index.js", From e27a58a5709ebe00ebd09785898f3cd2844aede1 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Fri, 1 Mar 2024 04:46:36 +0100 Subject: [PATCH 06/13] remove eslint-disable closes #9 --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index c4db0d0..5935e25 100755 --- a/src/index.js +++ b/src/index.js @@ -68,7 +68,6 @@ const serverStr = ` },` const proxyStr = ` proxy: { - // eslint-disable-next-line no-useless-escape '^(.+)\\\\.php': 'http://localhost:8000/', },` if (!viteConfigFileContent.match(regexStartOfServer)) { From d9541c011479aad43fc44574f236f57e7acd5357 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Fri, 1 Mar 2024 05:01:37 +0100 Subject: [PATCH 07/13] use npm create to bootstrap the demo app closes #10 --- .gitignore | 2 +- README.md | 11 ++++++++++- package.json | 2 +- src/index.js | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 808ffe5..f510506 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules/ -demo/ +demo-app/ .DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 8f0cc66..6c1d612 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,16 @@ Report bugs in the [issues list](https://github.com/scriptPilot/add-php-backend/ ## Maintainer 1. Apply changes -2. Run `npm run backend` to build the `demo` folder +2. Run `npm run demo` to build and start the `demo-app` 3. Commit changes with an issue (closure) reference 4. Run `npm version patch | minor | major` and push changes 5. Let the workflow manage the release to GitHub and NPM + +## Maintainer + +1. Apply changes to the code +2. Run `npm run demo` to build and start the `demo-app` +3. Apply changes to the `README.md` file and screenshots +4. Commit changes with an issue (closure) reference +5. Run `npm version patch | minor | major` and push changes +6. Let the workflow manage the release to GitHub and NPM diff --git a/package.json b/package.json index ed66ae0..9ed3f3b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "type": "module", "scripts": { "test": "", - "backend": "rm -rf demo && node . && cd demo && npm run backend", + "demo": "rm -rf demo-app && npm create vite demo-app -- --template react && node . && cd demo-app && npm install && npm run dev", "preversion": "npm install && npm test" }, "repository": { diff --git a/src/index.js b/src/index.js index 5935e25..6130c59 100755 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,7 @@ import fs from 'fs-extra' const scriptFolder = path.dirname(url.fileURLToPath(import.meta.url)) const processFolder = process.cwd() const isDevMode = processFolder === path.resolve(scriptFolder, '..') -const appFolder = isDevMode ? path.resolve(scriptFolder, '../demo') : processFolder +const appFolder = isDevMode ? path.resolve(scriptFolder, '../demo-app') : processFolder const templateFolder = path.resolve(scriptFolder, 'templates') // Define files From ec9f3c746f2ccb59ce82ee2af7275e3f56624c16 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Fri, 1 Mar 2024 05:01:46 +0100 Subject: [PATCH 08/13] 1.9.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8b2e14f..e369262 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.8.3", + "version": "1.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.8.3", + "version": "1.9.0", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 9ed3f3b..4cb8dd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.8.3", + "version": "1.9.0", "description": "", "main": "src/index.js", "bin": "src/index.js", From a45580b69618b2e98cbdbb80164673d1118c5593 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 3 Mar 2024 20:34:19 +0100 Subject: [PATCH 09/13] multi tenant support by default closes #11 --- src/templates/public/api.php | 38 ++++++++++++++++++++++++------------ src/templates/schema.sql | 7 ++++--- src/templates/testdata.sql | 3 --- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/templates/public/api.php b/src/templates/public/api.php index d14e7c9..85f792e 100644 --- a/src/templates/public/api.php +++ b/src/templates/public/api.php @@ -1,44 +1,58 @@ MYSQL_DATABASE === 'development', - // Database Credentials + // Credentials 'address' => MYSQL_HOST, 'database' => MYSQL_DATABASE, 'username' => MYSQL_USERNAME, 'password' => MYSQL_PASSWORD, - // Database Authentication - 'middlewares' => 'dbAuth,authorization', + // Middlewares + 'middlewares' => 'dbAuth,authorization,multiTenancy', + + // Database authentication 'dbAuth.mode' => 'optional', 'dbAuth.registerUser' => '1', + 'dbAuth.passwordLength' => '3', + + // Database Authorization 'authorization.tableHandler' => function ($operation, $tableName) { + + // No access to the users table if ($tableName === 'users') return false; + + // Access to all other tables return true; - } - + + }, + + // Multi Tenancy + 'multiTenancy.handler' => function ($operation, $tableName) { + + // For all tables, limit access to the current user + return ['userId' => $_SESSION['user']['id'] ?? 0]; + + }, + ]); // Initialization diff --git a/src/templates/schema.sql b/src/templates/schema.sql index 46c62fb..2f86c63 100644 --- a/src/templates/schema.sql +++ b/src/templates/schema.sql @@ -1,11 +1,12 @@ CREATE TABLE IF NOT EXISTS `users` ( - `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `id` INTEGER(8) NOT NULL PRIMARY KEY AUTO_INCREMENT, `username` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE IF NOT EXISTS `tasks` ( - `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, - `title` VARCHAR(255) NOT NULL, + `id` INTEGER(8) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `userId` INTEGER(8) NOT NULL DEFAULT 0, + `title` VARCHAR(255) NOT NULL DEFAULT "", `done` TINYINT(1) NOT NULL DEFAULT 0 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; \ No newline at end of file diff --git a/src/templates/testdata.sql b/src/templates/testdata.sql index 7732132..4d13f7f 100644 --- a/src/templates/testdata.sql +++ b/src/templates/testdata.sql @@ -1,5 +1,2 @@ -INSERT IGNORE INTO `users` (`id`, `username`, `password`) -VALUES (1, "root", "cm9vdA=="); - INSERT IGNORE INTO `tasks` (`id`, `title`, `done`) VALUES (1, "First Task", 1), (2, "Second Task", 0), (3, "Third Task", 1); \ No newline at end of file From fa4c773df6f63c6a073254f6fee5691ded2b3b29 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 3 Mar 2024 20:34:21 +0100 Subject: [PATCH 10/13] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6c1d612..e1f5cee 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ You might be interested in a simple [Synchronization between local IndexedDB and - Run `npm run backend` to start the backend - Open the PHP server at http://localhost:8000 + - API endpoint at http://localhost:8000/api.php [.../records/tasks](http://localhost:8000/api.php/records/tasks) - Open phpMyAdmin at http://localhost:8080 - Login with username `root` and password `root` - Use the PHP CRUD API in frontend with `/api.php` From f190a7e8daf449abec4728aeb9dda7eb54df1c6a Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 3 Mar 2024 20:35:21 +0100 Subject: [PATCH 11/13] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1f5cee..f86cbdd 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ You might be interested in a simple [Synchronization between local IndexedDB and - Run `npm run backend` to start the backend - Open the PHP server at http://localhost:8000 - - API endpoint at http://localhost:8000/api.php [.../records/tasks](http://localhost:8000/api.php/records/tasks) + - API endpoint at http://localhost:8000/api.php + - example: http://localhost:8000/api.php/records/tasks - Open phpMyAdmin at http://localhost:8080 - Login with username `root` and password `root` - Use the PHP CRUD API in frontend with `/api.php` From 9e8f9d1683643eeba7c2d12f6ba69235eab6249d Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 3 Mar 2024 20:35:32 +0100 Subject: [PATCH 12/13] 1.10.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e369262..a7573ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.9.0", + "version": "1.10.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.9.0", + "version": "1.10.0", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 4cb8dd4..651f1e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.9.0", + "version": "1.10.0", "description": "", "main": "src/index.js", "bin": "src/index.js", From 1a5ec1822871ae54b327e3610df4481319fd50e0 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Wed, 14 May 2025 18:27:14 +0200 Subject: [PATCH 13/13] Update README.md --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index f86cbdd..5ccf3f9 100644 --- a/README.md +++ b/README.md @@ -54,14 +54,6 @@ Report bugs in the [issues list](https://github.com/scriptPilot/add-php-backend/ ## Maintainer -1. Apply changes -2. Run `npm run demo` to build and start the `demo-app` -3. Commit changes with an issue (closure) reference -4. Run `npm version patch | minor | major` and push changes -5. Let the workflow manage the release to GitHub and NPM - -## Maintainer - 1. Apply changes to the code 2. Run `npm run demo` to build and start the `demo-app` 3. Apply changes to the `README.md` file and screenshots