Initial commit - CMS Gov Bapenda Garut dengan EditorJS

This commit is contained in:
2026-01-05 06:47:36 +07:00
commit bd649bd5f2
634 changed files with 215640 additions and 0 deletions

View File

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateRolesTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 50,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('name');
$this->forge->createTable('roles', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('roles');
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateUsersTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'role_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'username' => [
'type' => 'VARCHAR',
'constraint' => 100,
],
'email' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'phone_number' => [
'type' => 'VARCHAR',
'constraint' => 20,
'null' => true,
],
'password_hash' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'telegram_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'null' => true,
],
'is_active' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 1,
],
'last_login_at' => [
'type' => 'DATETIME',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('username');
$this->forge->addUniqueKey('email');
$this->forge->addUniqueKey('phone_number');
$this->forge->addUniqueKey('telegram_id');
$this->forge->addKey('role_id');
$this->forge->addForeignKey('role_id', 'roles', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('users', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('users');
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateNewsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'slug' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'content' => [
'type' => 'LONGTEXT',
],
'status' => [
'type' => 'ENUM',
'constraint' => ['draft', 'published'],
'default' => 'draft',
],
'published_at' => [
'type' => 'DATETIME',
'null' => true,
],
'created_by' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('slug');
$this->forge->addKey('created_by');
$this->forge->addKey('status');
$this->forge->addForeignKey('created_by', 'users', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('news', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('news');
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreatePagesTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'slug' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'content' => [
'type' => 'LONGTEXT',
],
'status' => [
'type' => 'ENUM',
'constraint' => ['draft', 'published'],
'default' => 'draft',
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('slug');
$this->forge->addKey('status');
$this->forge->createTable('pages', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('pages');
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateAuditLogsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'user_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => true,
],
'action' => [
'type' => 'VARCHAR',
'constraint' => 100,
],
'ip_address' => [
'type' => 'VARCHAR',
'constraint' => 45,
],
'user_agent' => [
'type' => 'TEXT',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('user_id');
$this->forge->addKey('action');
$this->forge->addKey('created_at');
$this->forge->addForeignKey('user_id', 'users', 'id', 'SET NULL', 'CASCADE');
$this->forge->createTable('audit_logs', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('audit_logs');
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateSettingsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'key' => [
'type' => 'VARCHAR',
'constraint' => '100',
],
'value' => [
'type' => 'TEXT',
'null' => true,
],
'description' => [
'type' => 'VARCHAR',
'constraint' => '255',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('key');
$this->forge->createTable('settings', true);
}
public function down()
{
$this->forge->dropTable('settings', true);
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
/**
* Migration untuk membuat tabel login_attempts
*
* Tabel ini digunakan untuk:
* - Mencatat semua percobaan login (berhasil dan gagal)
* - Monitoring aktivitas mencurigakan
* - Implementasi account lockout
* - Audit trail untuk keamanan
*/
class CreateLoginAttemptsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'ip_address' => [
'type' => 'VARCHAR',
'constraint' => '45',
'comment' => 'IP address dari percobaan login',
],
'username' => [
'type' => 'VARCHAR',
'constraint' => '100',
'null' => true,
'comment' => 'Username yang dicoba (null jika user tidak ditemukan)',
],
'user_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => true,
'comment' => 'ID user jika login berhasil',
],
'success' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
'comment' => '1 = berhasil, 0 = gagal',
],
'user_agent' => [
'type' => 'TEXT',
'null' => true,
'comment' => 'User agent browser',
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('ip_address');
$this->forge->addKey('username');
$this->forge->addKey('user_id');
$this->forge->addKey('created_at');
// Index composite untuk query cepat berdasarkan IP dan waktu
$this->forge->addKey(['ip_address', 'created_at']);
// Index composite untuk query berdasarkan username dan waktu
$this->forge->addKey(['username', 'created_at']);
$this->forge->createTable('login_attempts', true);
}
public function down()
{
$this->forge->dropTable('login_attempts', true);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class UpdatePagesTableForEditorJs extends Migration
{
public function up()
{
$fields = [
'content_json' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content',
],
'content_html' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content_json',
],
'excerpt' => [
'type' => 'TEXT',
'null' => true,
'after' => 'content_html',
],
'featured_image' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => true,
'after' => 'excerpt',
],
];
$this->forge->addColumn('pages', $fields);
}
public function down()
{
$this->forge->dropColumn('pages', ['content_json', 'content_html', 'excerpt', 'featured_image']);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class UpdateNewsTableForEditorJs extends Migration
{
public function up()
{
$fields = [
'content_json' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content',
],
'content_html' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content_json',
],
'excerpt' => [
'type' => 'TEXT',
'null' => true,
'after' => 'content_html',
],
];
$this->forge->addColumn('news', $fields);
}
public function down()
{
$this->forge->dropColumn('news', ['content_json', 'content_html', 'excerpt']);
}
}