Skip to content

Commit

Permalink
Merge pull request #10 from tattersoftware/bugs
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
MGatner authored Jul 13, 2020
2 parents 6ae8858 + 6d97ee0 commit 0e1d9c4
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 42 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/codeigniter4-module.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PHPUnit

on:
pull_request:
branches:
- develop

jobs:
main:
name: Build and test

strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']

runs-on: ubuntu-latest

if: "!contains(github.event.head_commit.message, '[ci skip]')"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl, phpunit
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
coverage: xdebug

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Tatter\Schemas
Database schema management, for CodeIgniter 4

[![](https://github.com/tattersoftware/codeigniter4-schemas/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-schemas/actions?query=workflow%3APHPUnit)

## Quick Start

1. Install with Composer: `> composer require tatter/schemas`
Expand Down Expand Up @@ -117,6 +119,11 @@ Currently supported handlers:

* Cache

## Database Support

All CodeIgniter 4 database drivers work but due to some differences in index handling they
may not all report the same results. Example: see skipped tests for SQLite3.

## Development

The eventual goal is to support mapping from and deploying to any source. Planned handler
Expand Down
2 changes: 1 addition & 1 deletion src/Collectors/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function display(): string
foreach ($this->schema->tables as $table)
{
$html .= '<h4>' . $table->name . '</h4>' . PHP_EOL;
$html .= '<pre><code>' . print_r($table, true) . '</pre></code>' . PHP_EOL;
$html .= '<pre style="color: gray;"><code>' . print_r($table, true) . '</pre></code>' . PHP_EOL;
}

return $html;
Expand Down
22 changes: 14 additions & 8 deletions src/Commands/Schemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class Schemas extends BaseCommand
{
protected $group = 'Schemas';
protected $name = 'schemas';
protected $description = 'Manage database schemas.';
protected $group = 'Schemas';
protected $name = 'schemas';
protected $description = 'Manage database schemas.';

protected $usage = "schemas [-draft handler1,handler2,...] [-archive handler1,... | -print]";
protected $options = [
'-draft' => 'Handler(s) for drafting the schema ("database", "model", etc)',
Expand All @@ -18,10 +18,16 @@ class Schemas extends BaseCommand
];

public function run(array $params)
{
$schemas = service('schemas');
{
// Always use a clean library with automation disabled
$config = config('Schemas');

$config->automate = [
'draft' => false,
'archive' => false,
'read' => false,
];
$schemas = new \Tatter\Schemas\Schemas($config, null);

// Determine draft handlers
if ($drafters = $params['-draft'] ?? CLI::getOption('draft'))
{
Expand Down Expand Up @@ -72,7 +78,7 @@ public function run(array $params)
$this->showError($e);
}

if (! $result)
if (empty($result))
{
CLI::write('Archive failed!', 'red');
foreach ($schemas->getErrors() as $error)
Expand Down
3 changes: 2 additions & 1 deletion src/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Services extends BaseService
{
public static function schemas(BaseConfig $config = null, bool $getShared = true)
{
if ($getShared) {
if ($getShared)
{
return static::getSharedInstance('schemas', $config);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Drafter/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function draft(): ?Schema
// Build the relation
$relation = new Relation();
$relation->type = 'belongsTo';
$relation->singleton = 'belongsTo';
$relation->singleton = true;
$relation->table = $tableName2;
$relation->pivots = [$pivot];

Expand Down
9 changes: 8 additions & 1 deletion src/Structures/Mergeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ public function merge(?Mergeable $object): Mergeable
{
foreach ($item as $mykey => $value)
{
$this->$key->$mykey = $value;
if ($item instanceof Mergeable && $this->$key instanceof Mergeable)
{
$this->$key->merge($item);
}
else
{
$this->$key->$mykey = $value;
}
}
}
else
Expand Down
10 changes: 10 additions & 0 deletions tests/draft/DatabaseDrafterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function testIgnoredTables()

public function testDetectsAllRelationships()
{
if ($this->db->DBDriver === 'SQLite3')
{
$this->markTestSkipped('SQLite3 does not always support foreign key reads.');
}

$relationsCount = 0;
foreach ($this->schema->tables as $table)
{
Expand Down Expand Up @@ -82,6 +87,11 @@ public function testHasMany()

public function testHasManyFromForeignKey()
{
if ($this->db->DBDriver === 'SQLite3')
{
$this->markTestSkipped('SQLite3 does not always support foreign key reads.');
}

$table1 = $this->schema->tables->workers;
$table2 = $this->schema->tables->lawsuits;

Expand Down
15 changes: 15 additions & 0 deletions tests/service/LiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function testDatabaseToCache()

public function testDatabaseMergeFile()
{
if ($this->db->DBDriver === 'SQLite3')
{
$this->markTestSkipped('SQLite3 does not always support foreign key reads.');
}

$databaseHandler = new DatabaseHandler($this->config, 'tests');
$fileHandler = new DirectoryHandler($this->config);

Expand All @@ -36,6 +41,11 @@ public function testDatabaseMergeFile()

public function testMergeAllDrafters()
{
if ($this->db->DBDriver === 'SQLite3')
{
$this->markTestSkipped('SQLite3 does not always support foreign key reads.');
}

$databaseHandler = new DatabaseHandler($this->config, 'tests');
$modelHandler = new ModelHandler($this->config);
$fileHandler = new DirectoryHandler($this->config);
Expand All @@ -62,6 +72,11 @@ public function testGetReturnsSchemaWithReader()

public function testAutoRead()
{
if ($this->db->DBDriver === 'SQLite3')
{
$this->markTestSkipped('SQLite3 does not always support foreign key reads.');
}

$this->config->automate['read'] = true;

// Draft & archive a copy of the schema so we can test reading it
Expand Down

0 comments on commit 0e1d9c4

Please sign in to comment.