From 08ecd46f94c2f963fc40b41788f8a33fbe4d49e4 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 00:41:52 +0100 Subject: [PATCH 01/26] prepend backend to dev closes #6 --- README.md | 2 +- src/index.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 671f002..cbc0efe 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h - `schema.sql` contains the database schema and updates to it - `testdata.sql` contains test data only for development - the package main script will **modify some files** in your project folder: - - add a `backend` script to the `package.json` file + - add a `backend` script to the `package.json` file and prepend it to `dev` - add a proxy server config for PHP files to the Vite config file - add `vendor/` and `credentials.php` to the `.gitignore` file diff --git a/src/index.js b/src/index.js index b0fe02a..ece1702 100755 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,7 @@ let viteConfigFile = null shell.exec(`cp -Rn "${templateFolder}/" "${appFolder}/"`) // Create package.json file if not exists -if (!fs.existsSync(packageFile)) fs.writeFileSync(packageFile, '{}') +if (!fs.existsSync(packageFile)) fs.writeFileSync(packageFile, '{ "scripts": { "dev": "vite" } }') // Search for vite config file viteConfigFile = @@ -52,6 +52,7 @@ const nextPackageFileJson = { ...packageFileJson, scripts: { ...packageFileJson.scripts, + dev: 'npm run backend' + (packageFileJson.scripts?.dev ? ' && ' + packageFileJson.scripts.dev : ''), backend: '(docker stop $(docker ps -a -q) || true) && (docker rm -f $(docker ps -a -q) || true) && (docker volume rm $(docker volume ls -q) || true) && docker compose up -d --build', } } From b7d022a41e1b8fd01ab82f510894a7d5e290a3c5 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 00:42:10 +0100 Subject: [PATCH 02/26] 1.7.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 2fb98b6..99c69c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.6.0", + "version": "1.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.6.0", + "version": "1.7.0", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index ac5ea9d..6c8dd46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.6.0", + "version": "1.7.0", "description": "", "main": "src/index.js", "bin": "src/index.js", From 50b6b652d15a7059f28196149fa175ad08ff0109 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 01:55:08 +0100 Subject: [PATCH 03/26] Update index.js --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index ece1702..c4db0d0 100755 --- a/src/index.js +++ b/src/index.js @@ -52,7 +52,7 @@ const nextPackageFileJson = { ...packageFileJson, scripts: { ...packageFileJson.scripts, - dev: 'npm run backend' + (packageFileJson.scripts?.dev ? ' && ' + packageFileJson.scripts.dev : ''), + dev: (packageFileJson.scripts?.dev?.startsWith('npm run backend') ? packageFileJson.scripts.dev : 'npm run backend' + (packageFileJson.scripts?.dev ? ' && ' + packageFileJson.scripts.dev : '')), backend: '(docker stop $(docker ps -a -q) || true) && (docker rm -f $(docker ps -a -q) || true) && (docker volume rm $(docker volume ls -q) || true) && docker compose up -d --build', } } From 19a507fb1a9e0d11bf49e4ae34af1813ac374ebb Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 01:55:21 +0100 Subject: [PATCH 04/26] 1.7.1 --- 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 99c69c0..9499108 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.7.0", + "version": "1.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.7.0", + "version": "1.7.1", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 6c8dd46..4545932 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.7.0", + "version": "1.7.1", "description": "", "main": "src/index.js", "bin": "src/index.js", From a4021e98bccc3d5fe529ea0639d9b7657854eee1 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 02:06:00 +0100 Subject: [PATCH 05/26] simplify config closes #7 --- src/templates/public/api.php | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/templates/public/api.php b/src/templates/public/api.php index d340de4..d14e7c9 100644 --- a/src/templates/public/api.php +++ b/src/templates/public/api.php @@ -34,31 +34,10 @@ 'middlewares' => 'dbAuth,authorization', 'dbAuth.mode' => 'optional', 'dbAuth.registerUser' => '1', - 'dbAuth.returnedColumns' => 'id,username', - 'authorization.tableHandler' => function ($operation, $tableName) { - // Disallow user table for delete operations - if ($operation === 'delete' && $tableName === 'users') { - return false; - } - // No other table limitation + 'authorization.tableHandler' => function ($operation, $tableName) { + if ($tableName === 'users') return false; return true; - }, - 'authorization.columnHandler' => function ($operation, $tableName, $columnName) { - // Hide user/password column - if (($operation === 'read' || $operation === 'list') && $tableName === 'users' && $columnName === 'password') { - return false; - } - // No other column limitation - return true; - }, - 'authorization.recordHandler' => function ($operation, $tableName) { - // Limit user records to same user - if ($tableName === 'users' && $operation !== 'create') { - return 'filter=id,eq,' . USERID; - } - // No other record limitation - return true; - } + } ]); From 2c3b0139ecf260ba8f44aa9cc8708f5249a64707 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 02:06:11 +0100 Subject: [PATCH 06/26] 1.8.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 9499108..4734f98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.7.1", + "version": "1.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.7.1", + "version": "1.8.0", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 4545932..8bb04b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.7.1", + "version": "1.8.0", "description": "", "main": "src/index.js", "bin": "src/index.js", From b6b2f0f32c9ea25c12bf6bd5e43627335a9950d6 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 22:13:14 +0100 Subject: [PATCH 07/26] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index cbc0efe..9a86776 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h npx add-php-backend ``` +You might be interested in a simple [JavaScript API Wrapper](https://github.com/scriptPilot/js-php-mysql-crud-api) or [PouchDB + MySQL](https://github.com/scriptPilot/pouchdb-mysql/). + ## Usage - Run `npm run backend` to start the backend From 03c2431fb22790a0f849c8fa76e17c6e040e3c32 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 22:13:40 +0100 Subject: [PATCH 08/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a86776..d9f553b 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h npx add-php-backend ``` -You might be interested in a simple [JavaScript API Wrapper](https://github.com/scriptPilot/js-php-mysql-crud-api) or [PouchDB + MySQL](https://github.com/scriptPilot/pouchdb-mysql/). - ## Usage - Run `npm run backend` to start the backend @@ -28,6 +26,8 @@ You might be interested in a simple [JavaScript API Wrapper](https://github.com/ - Login with username `root` and password `root` - Use the PHP CRUD API in frontend with `/api.php` +**You might be interested in a simple [JavaScript API Wrapper](https://github.com/scriptPilot/js-php-mysql-crud-api) or [PouchDB + MySQL](https://github.com/scriptPilot/pouchdb-mysql/).** + ## How it works - **no dependency** will be added to the repository From 284f46444f32fe32402cc24321deb7f74c12606c Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 22:14:28 +0100 Subject: [PATCH 09/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9f553b..c95381e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h - Login with username `root` and password `root` - Use the PHP CRUD API in frontend with `/api.php` -**You might be interested in a simple [JavaScript API Wrapper](https://github.com/scriptPilot/js-php-mysql-crud-api) or [PouchDB + MySQL](https://github.com/scriptPilot/pouchdb-mysql/).** +**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/).** ## How it works From 9291a2fea7b3e97aeb0ca79d1788f7ce366f3c81 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sat, 24 Feb 2024 22:22:00 +0100 Subject: [PATCH 10/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c95381e..6f30241 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h npx add-php-backend ``` +💡 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/). + ## Usage - Run `npm run backend` to start the backend @@ -26,8 +28,6 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h - Login with username `root` and password `root` - Use the PHP CRUD API in frontend with `/api.php` -**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/).** - ## How it works - **no dependency** will be added to the repository From 0acb12e8ace1352541fc3e071dd4d954ea75425d Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 25 Feb 2024 11:33:04 +0100 Subject: [PATCH 11/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6f30241..106f917 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ 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/). + ## Installation 1. Install [Docker](https://www.docker.com/) and [Node.js](https://nodejs.org/) @@ -18,8 +20,6 @@ Add [PHP](https://www.php.net/), [Composer](https://getcomposer.org/), [MySQL](h npx add-php-backend ``` -💡 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/). - ## Usage - Run `npm run backend` to start the backend From 240cddec781d65a9a06920bb24336cc6d463135d Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 25 Feb 2024 21:20:00 +0100 Subject: [PATCH 12/26] simplification; capital keywords --- src/templates/schema.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/templates/schema.sql b/src/templates/schema.sql index 5ffb15f..7d8c81a 100644 --- a/src/templates/schema.sql +++ b/src/templates/schema.sql @@ -1,11 +1,11 @@ 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; + `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `username` VARCHAR(255) NOT NULL, + `password` VARCHAR(255) NOT NULL +); 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 -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; \ No newline at end of file + `id` INTEGER(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `title` VARCHAR(255) NOT NULL, + `done` INTEGER(1) NOT NULL DEFAULT 0 +); \ No newline at end of file From 4df3e407d49d71dc95ce5a6e1a659b03d089fb48 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 25 Feb 2024 21:20:09 +0100 Subject: [PATCH 13/26] 1.8.1 --- 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 4734f98..c2d048a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "add-php-backend", - "version": "1.8.0", + "version": "1.8.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "add-php-backend", - "version": "1.8.0", + "version": "1.8.1", "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", diff --git a/package.json b/package.json index 8bb04b2..4be18f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-php-backend", - "version": "1.8.0", + "version": "1.8.1", "description": "", "main": "src/index.js", "bin": "src/index.js", From ff9b85679bda4c7df6be9de4fd1de110641c0718 Mon Sep 17 00:00:00 2001 From: scriptPilot Date: Sun, 25 Feb 2024 23:32:07 +0100 Subject: [PATCH 14/26] 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 15/26] 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 16/26] 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 17/26] 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 18/26] 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 19/26] 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 20/26] 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 21/26] 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 22/26] 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 23/26] 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 24/26] 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 25/26] 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 26/26] 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