umstellung auf shared codeigniter und postgres php8.2
This commit is contained in:
@@ -1,172 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class Migration_Create_test_tables extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// User Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 80],
|
||||
'email' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
'country' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
])->addKey('id', true)->createTable('user', true);
|
||||
|
||||
// Job Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'description' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
'created_at' => ['type' => 'INTEGER', 'constraint' => 11, 'null' => true],
|
||||
'updated_at' => ['type' => 'INTEGER', 'constraint' => 11, 'null' => true],
|
||||
'deleted_at' => ['type' => 'INTEGER', 'constraint' => 11, 'null' => true],
|
||||
])->addKey('id', true)->createTable('job', true);
|
||||
|
||||
// Misc Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('misc', true);
|
||||
|
||||
// Database Type test table
|
||||
// missing types :
|
||||
// TINYINT,MEDIUMINT,BIT,YEAR,BINARY , VARBINARY, TINYTEXT,LONGTEXT,YEAR,JSON,Spatial data types
|
||||
// id must be interger else SQLite3 error on not null for autoinc field
|
||||
$data_type_fields = [
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true],
|
||||
'type_varchar' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
|
||||
'type_char' => ['type' => 'CHAR', 'constraint' => 10, 'null' => true],
|
||||
'type_text' => ['type' => 'TEXT', 'null' => true],
|
||||
'type_smallint' => ['type' => 'SMALLINT', 'null' => true],
|
||||
'type_integer' => ['type' => 'INTEGER', 'null' => true],
|
||||
'type_float' => ['type' => 'FLOAT', 'null' => true],
|
||||
'type_numeric' => ['type' => 'NUMERIC', 'constraint' => '18,2', 'null' => true],
|
||||
'type_date' => ['type' => 'DATE', 'null' => true],
|
||||
'type_time' => ['type' => 'TIME', 'null' => true],
|
||||
'type_datetime' => ['type' => 'DATETIME', 'null' => true],
|
||||
'type_timestamp' => ['type' => 'TIMESTAMP', 'null' => true],
|
||||
'type_bigint' => ['type' => 'BIGINT', 'null' => true],
|
||||
'type_real' => ['type' => 'REAL', 'null' => true],
|
||||
'type_enum' => ['type' => 'ENUM', 'constraint' => ['appel', 'pears'], 'null' => true],
|
||||
'type_set' => ['type' => 'SET', 'constraint' => ['one', 'two'], 'null' => true],
|
||||
'type_mediumtext' => ['type' => 'MEDIUMTEXT', 'null' => true],
|
||||
'type_double' => ['type' => 'DOUBLE', 'null' => true],
|
||||
'type_decimal' => ['type' => 'DECIMAL', 'constraint' => '18,4', 'null' => true],
|
||||
'type_blob' => ['type' => 'BLOB', 'null' => true],
|
||||
'type_boolean' => ['type' => 'BOOLEAN', 'null' => true],
|
||||
];
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
unset(
|
||||
$data_type_fields['type_real'],
|
||||
$data_type_fields['type_decimal']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'SQLSRV') {
|
||||
unset($data_type_fields['type_timestamp']);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') {
|
||||
unset(
|
||||
$data_type_fields['type_enum'],
|
||||
$data_type_fields['type_set'],
|
||||
$data_type_fields['type_mediumtext'],
|
||||
$data_type_fields['type_double'],
|
||||
$data_type_fields['type_blob']
|
||||
);
|
||||
}
|
||||
|
||||
$this->forge->addField($data_type_fields)->addKey('id', true)->createTable('type_test', true);
|
||||
|
||||
// Empty Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'created_at' => ['type' => 'DATE', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATE', 'null' => true],
|
||||
])->addKey('id', true)->createTable('empty', true);
|
||||
|
||||
// Secondary Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('secondary', true);
|
||||
|
||||
// Stringify Primary key Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'VARCHAR', 'constraint' => 3],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('stringifypkey', true);
|
||||
|
||||
// Table without auto increment field
|
||||
$this->forge->addField([
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 40, 'unique' => true],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('key', true)->createTable('without_auto_increment', true);
|
||||
|
||||
// IP Table
|
||||
$this->forge->addField([
|
||||
'ip' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
'ip2' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
])->createTable('ip_table', true);
|
||||
|
||||
// Database session table
|
||||
if ($this->db->DBDriver === 'MySQLi') {
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false],
|
||||
'timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL',
|
||||
'data' => ['type' => 'BLOB', 'null' => false],
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->createTable('ci_sessions', true);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false],
|
||||
'ip_address inet NOT NULL',
|
||||
'timestamp timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL',
|
||||
"data bytea DEFAULT '' NOT NULL",
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->createTable('ci_sessions', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('user', true);
|
||||
$this->forge->dropTable('job', true);
|
||||
$this->forge->dropTable('misc', true);
|
||||
$this->forge->dropTable('type_test', true);
|
||||
$this->forge->dropTable('empty', true);
|
||||
$this->forge->dropTable('secondary', true);
|
||||
$this->forge->dropTable('stringifypkey', true);
|
||||
$this->forge->dropTable('without_auto_increment', true);
|
||||
$this->forge->dropTable('ip_table', true);
|
||||
|
||||
if (in_array($this->db->DBDriver, ['MySQLi', 'Postgre'], true)) {
|
||||
$this->forge->dropTable('ci_sessions', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class ExampleMigration extends Migration
|
||||
{
|
||||
protected $DBGroup = 'tests';
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addField('id');
|
||||
$this->forge->addField([
|
||||
'name' => ['type' => 'varchar', 'constraint' => 31],
|
||||
'uid' => ['type' => 'varchar', 'constraint' => 31],
|
||||
'class' => ['type' => 'varchar', 'constraint' => 63],
|
||||
'icon' => ['type' => 'varchar', 'constraint' => 31],
|
||||
'summary' => ['type' => 'varchar', 'constraint' => 255],
|
||||
'created_at' => ['type' => 'datetime', 'null' => true],
|
||||
'updated_at' => ['type' => 'datetime', 'null' => true],
|
||||
'deleted_at' => ['type' => 'datetime', 'null' => true],
|
||||
]);
|
||||
|
||||
$this->forge->addKey('name');
|
||||
$this->forge->addKey('uid');
|
||||
$this->forge->addKey(['deleted_at', 'id']);
|
||||
$this->forge->addKey('created_at');
|
||||
|
||||
$this->forge->createTable('factories');
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('factories');
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class AnotherSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$row = [
|
||||
'name' => 'Jerome Lohan',
|
||||
'email' => 'jlo@lohanenterprises.com',
|
||||
'country' => 'UK',
|
||||
];
|
||||
|
||||
$this->db->table('user')->insert($row);
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class CITestSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// Job Data
|
||||
$data = [
|
||||
'user' => [
|
||||
[
|
||||
'name' => 'Derek Jones',
|
||||
'email' => 'derek@world.com',
|
||||
'country' => 'US',
|
||||
],
|
||||
[
|
||||
'name' => 'Ahmadinejad',
|
||||
'email' => 'ahmadinejad@world.com',
|
||||
'country' => 'Iran',
|
||||
],
|
||||
[
|
||||
'name' => 'Richard A Causey',
|
||||
'email' => 'richard@world.com',
|
||||
'country' => 'US',
|
||||
],
|
||||
[
|
||||
'name' => 'Chris Martin',
|
||||
'email' => 'chris@world.com',
|
||||
'country' => 'UK',
|
||||
],
|
||||
],
|
||||
'job' => [
|
||||
[
|
||||
'name' => 'Developer',
|
||||
'description' => 'Awesome job, but sometimes makes you bored',
|
||||
],
|
||||
[
|
||||
'name' => 'Politician',
|
||||
'description' => 'This is not really a job',
|
||||
],
|
||||
[
|
||||
'name' => 'Accountant',
|
||||
'description' => 'Boring job, but you will get free snack at lunch',
|
||||
],
|
||||
[
|
||||
'name' => 'Musician',
|
||||
'description' => 'Only Coldplay can actually called Musician',
|
||||
],
|
||||
],
|
||||
'misc' => [
|
||||
[
|
||||
'key' => '\\xxxfoo456',
|
||||
'value' => 'Entry with \\xxx',
|
||||
],
|
||||
[
|
||||
'key' => '\\%foo456',
|
||||
'value' => 'Entry with \\%',
|
||||
],
|
||||
[
|
||||
'key' => 'spaces and tabs',
|
||||
'value' => ' One two three tab',
|
||||
],
|
||||
],
|
||||
'stringifypkey' => [
|
||||
[
|
||||
'id' => 'A01',
|
||||
'value' => 'test',
|
||||
],
|
||||
],
|
||||
'without_auto_increment' => [
|
||||
[
|
||||
'key' => 'key',
|
||||
'value' => 'value',
|
||||
],
|
||||
],
|
||||
'type_test' => [
|
||||
[
|
||||
'type_varchar' => 'test',
|
||||
'type_char' => 'test',
|
||||
'type_enum' => 'appel',
|
||||
'type_set' => 'one',
|
||||
'type_text' => 'test text',
|
||||
'type_mediumtext' => 'test medium text',
|
||||
'type_smallint' => 1,
|
||||
'type_integer' => 123,
|
||||
'type_float' => 10.1,
|
||||
'type_real' => 11.21,
|
||||
'type_double' => 23.22,
|
||||
'type_decimal' => 123123.2234,
|
||||
'type_numeric' => 123.23,
|
||||
'type_blob' => 'test blob',
|
||||
'type_date' => '2020-01-11T22:11:00.000+02:00',
|
||||
'type_time' => '2020-07-18T15:22:00.000+02:00',
|
||||
'type_datetime' => '2020-06-18T05:12:24.000+02:00',
|
||||
'type_timestamp' => '2019-07-18T21:53:21.000+02:00',
|
||||
'type_bigint' => 2342342,
|
||||
'type_boolean' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// set SQL times to more correct format
|
||||
if ($this->db->DBDriver === 'SQLite3') {
|
||||
$data['type_test'][0]['type_date'] = '2020/01/11';
|
||||
$data['type_test'][0]['type_time'] = '15:22:00';
|
||||
$data['type_test'][0]['type_datetime'] = '2020/06/18 05:12:24';
|
||||
$data['type_test'][0]['type_timestamp'] = '2019/07/18 21:53:21';
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
$data['type_test'][0]['type_time'] = '15:22:00';
|
||||
$data['type_test'][0]['type_boolean'] = true;
|
||||
unset(
|
||||
$data['type_test'][0]['type_enum'],
|
||||
$data['type_test'][0]['type_set'],
|
||||
$data['type_test'][0]['type_mediumtext'],
|
||||
$data['type_test'][0]['type_real'],
|
||||
$data['type_test'][0]['type_double'],
|
||||
$data['type_test'][0]['type_decimal'],
|
||||
$data['type_test'][0]['type_blob']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'SQLSRV') {
|
||||
$data['type_test'][0]['type_date'] = '2020-01-11';
|
||||
$data['type_test'][0]['type_time'] = '15:22:00.000';
|
||||
$data['type_test'][0]['type_datetime'] = '2020-06-18 05:12:24.000';
|
||||
|
||||
unset(
|
||||
$data['type_test'][0]['type_timestamp'],
|
||||
$data['type_test'][0]['type_enum'],
|
||||
$data['type_test'][0]['type_set'],
|
||||
$data['type_test'][0]['type_mediumtext'],
|
||||
$data['type_test'][0]['type_double'],
|
||||
$data['type_test'][0]['type_blob']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'MySQLi') {
|
||||
$data['ci_sessions'][] = [
|
||||
'id' => '1f5o06b43phsnnf8if6bo33b635e4p2o',
|
||||
'ip_address' => '127.0.0.1',
|
||||
'timestamp' => '2021-06-25 21:54:14',
|
||||
'data' => '__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";',
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
$data['ci_sessions'][] = [
|
||||
'id' => '1f5o06b43phsnnf8if6bo33b635e4p2o',
|
||||
'ip_address' => '127.0.0.1',
|
||||
'timestamp' => '2021-06-25 21:54:14.991403+02',
|
||||
'data' => '\x' . bin2hex('__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";'),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($data as $table => $dummy_data) {
|
||||
$this->db->table($table)->truncate();
|
||||
|
||||
foreach ($dummy_data as $single_dummy_data) {
|
||||
$this->db->table($table)->insert($single_dummy_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
tests/_support/Database/Seeds/ExampleSeeder.php
Normal file
41
tests/_support/Database/Seeds/ExampleSeeder.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class ExampleSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$factories = [
|
||||
[
|
||||
'name' => 'Test Factory',
|
||||
'uid' => 'test001',
|
||||
'class' => 'Factories\Tests\NewFactory',
|
||||
'icon' => 'fas fa-puzzle-piece',
|
||||
'summary' => 'Longer sample text for testing',
|
||||
],
|
||||
[
|
||||
'name' => 'Widget Factory',
|
||||
'uid' => 'widget',
|
||||
'class' => 'Factories\Tests\WidgetPlant',
|
||||
'icon' => 'fas fa-puzzle-piece',
|
||||
'summary' => 'Create widgets in your factory',
|
||||
],
|
||||
[
|
||||
'name' => 'Evil Factory',
|
||||
'uid' => 'evil-maker',
|
||||
'class' => 'Factories\Evil\MyFactory',
|
||||
'icon' => 'fas fa-book-dead',
|
||||
'summary' => 'Abandon all hope, ye who enter here',
|
||||
],
|
||||
];
|
||||
|
||||
$builder = $this->db->table('factories');
|
||||
|
||||
foreach ($factories as $factory) {
|
||||
$builder->insert($factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user