DataBridgeSchema

Manages database structure. All schema changes must go through this layer.


Installation


loadfunction("DataBridgeSchema");

Examples

Create Table


$schema = new DataBridgeSchema("tickets");
$schema->createTable([
  'id' => 'INT AUTO_INCREMENT PRIMARY KEY',
  'title' => 'VARCHAR(255)',
  'status' => 'VARCHAR(50)'
]);

Columns


$schema->addColumn("priority", "INT");
$schema->modifyColumn("priority", "INT DEFAULT 1");
$schema->dropColumn("priority");

Indexes


$schema->addIndex("idx_status", ["status"]);
$schema->dropIndex("idx_status");

Foreign Keys


$schema->addForeignKey("user_id", "users");

Extend Table


$schema = new DataBridgeSchema("incident_details");
$schema->extendTable("incidents");

API Reference

MethodDescription
createTable()Create table
addColumn()Add column
modifyColumn()Modify column
dropColumn()Drop column
addIndex()Add index
addForeignKey()Add FK
extendTable()Extend base table

Best Practices

  • Never modify base tables directly
  • Always use migrations

Anti-Patterns

  • Schema changes at runtime
  • Dropping tables in production