Skip to content

Commit

Permalink
Merge pull request #109 from xsist10/parse_create_statements
Browse files Browse the repository at this point in the history
Support parsing DDL create statements
  • Loading branch information
xsist10 authored Jun 1, 2024
2 parents b827016 + d8e66b6 commit 4b494ab
Show file tree
Hide file tree
Showing 32 changed files with 2,037 additions and 6,067 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
build/
cadfael.phar
.phpunit.result.cache
composer.lock
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,30 @@ The path to the executable will be in `./vendor/bin/`.

## Usage

You can run Cadfael directly against your database or you can run it against a file containing your MySQL table and schema creation statements.

For high quality results, we recommended running it against your database as there is significantly more information available for analysis (see the Advanced Usage section).

```bash
cadfael run --host 127.0.0.1 --username root --port 3306 [database_to_scan]
# Run cadfael against a specific MySQL schema in your database
cadfael run --host 127.0.0.1 --username root --port 3306 [schema_name]
```

However, sometimes you won't have access to run it against your database (either due to your environment or security considerations). You may find this option works better for CI/CD pipeline use.

```bash
# Run cadfael against the creation definitions in this file
cadfael run-statment resources/mysql/sample.sql
```

Please note that this is an *EXPERIMENTAL FEATURE* as this method uses a 3rd party library with some limitations so not all analysis features are supported at this moment.

### Advanced Usage

You can also include the `--performance_schema` flag if you wish to run checks against the [performance_schema](https://dev.mysql.com/doc/refman/8.0/en/performance-schema.html) schema which collect analytics about your server since the last time it was restarted. This is particularly useful if you want to see how your database is being used and detect issues related to queries, access of tables and heavy or badly optimized queries.
If you are running Cadfael against your database, you can also include the `--performance_schema` flag if you wish to run checks against the [performance_schema](https://dev.mysql.com/doc/refman/8.0/en/performance-schema.html) schema which collect analytics about your server since the last time it was restarted. This is particularly useful if you want to see how your database is being used and detect issues related to queries, access of tables and heavy or badly optimized queries.

For meaningful results you *should* run this against the database that is being used in production otherwise you'll only be checking against the metrics collected in your development environment.
**BUT FIRST** always speak to your DBA/Security people first before run random tools from the internet against your production database.
**BUT FIRST** always speak to your DBA/Security people before run random tools from the internet against your production database.

### Environmental Variables

Expand All @@ -77,7 +91,7 @@ MYSQL_HOST=127.0.0.1 MYSQL_USER=root MYSQL_PORT=3306 MYSQL_DATABASE=[database_to

### Output
```
Cadfael CLI Tool 0.2.6
Cadfael CLI Tool 0.3.3
Host: localhost:3306
User: [username]
Expand Down
2 changes: 2 additions & 0 deletions bin/cadfael
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php
use Symfony\Component\Console\Application;
use Composer\InstalledVersions as InstalledVersionsAlias;
use Cadfael\Cli\Command\RunCommand;
use Cadfael\Cli\Command\RunStatementCommand;
use Cadfael\Cli\Command\AboutCommand;

$version = InstalledVersionsAlias::getPrettyVersion('cadfael/cadfael');
Expand All @@ -25,4 +26,5 @@ $application->setName('Cadfael CLI');
$application->setVersion($version);
$application->add(new AboutCommand());
$application->add(new RunCommand());
$application->add(new RunStatementCommand());
$application->run();
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"doctrine/dbal": "^2.10",
"symfony/console": "^5.0",
"monolog/monolog": "^2.1",
"greenlion/php-sql-parser": "^4.5",
"ext-json": "*"
"greenlion/php-sql-parser": "dev-master",
"ext-json": "*",
"kodus/sql-split": "^2.0",
"league/flysystem": "^3.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
Expand Down
Loading

0 comments on commit 4b494ab

Please sign in to comment.