diff --git a/db/migrations/20210315235815_create_values.php b/db/migrations/20210315235815_create_values.php index 02d4c21..b99ad28 100644 --- a/db/migrations/20210315235815_create_values.php +++ b/db/migrations/20210315235815_create_values.php @@ -34,13 +34,21 @@ class CreateValues extends Phinx\Migration\AbstractMigration 'signed' => false, 'after' => 'value', ]) - ->addIndex(['currency_id'], [ + /*->addIndex(['currency_id'], [ 'name' => 'currency_id', 'unique' => false, ]) ->addIndex(['base_id'], [ 'name' => 'base_id', 'unique' => false, + ])*/ + ->addForeignKey(['currency_id'], 'currencies', ['id'], [ + 'delete' => 'CASCADE', + 'update' => 'CASCADE' + ]) + ->addForeignKey(['base_id'], 'currencies', ['id'], [ + 'delete' => 'CASCADE', + 'update' => 'CASCADE' ]) ->create(); /*$this->table('currencies', [ diff --git a/db/migrations/20210320020631_create_sources.php b/db/migrations/20210320020631_create_sources.php index 2b77479..64167be 100644 --- a/db/migrations/20210320020631_create_sources.php +++ b/db/migrations/20210320020631_create_sources.php @@ -53,9 +53,13 @@ final class CreateSources extends AbstractMigration 'encoding' => 'utf8mb4', 'after' => 'url', ]) - ->addIndex(['currency_id'], [ + /*->addIndex(['currency_id'], [ 'name' => 'currency_id', 'unique' => false, + ])*/ + ->addForeignKey(['currency_id'], 'currencies', ['id'], [ + 'delete' => 'CASCADE', + 'update' => 'CASCADE' ]) ->create(); } diff --git a/db/migrations/20210414015145_create_aliases.php b/db/migrations/20210414015145_create_aliases.php new file mode 100644 index 0000000..95572b7 --- /dev/null +++ b/db/migrations/20210414015145_create_aliases.php @@ -0,0 +1,59 @@ +table('aliases', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_general_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('currency_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'id', + ]) + ->addColumn('alias', 'string', [ + 'null' => false, + 'limit' => 100, + 'collation' => 'utf8mb4_general_ci', + 'encoding' => 'utf8mb4', + 'after' => 'currency_id', + ]) + /*->addIndex(['currency_id'], [ + 'name' => 'currency_id', + 'unique' => false, + ])*/ + ->addForeignKey(['currency_id'], 'currencies', ['id'], [ + 'delete' => 'CASCADE', + 'update' => 'CASCADE' + ]) + ->create(); + } +}