You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 line
1.2KB

  1. <?php
  2. declare(strict_types=1);
  3. use Core\Database;
  4. use Core\Migration;
  5. return new class extends Migration
  6. {
  7. public function up(Database $database): void
  8. {
  9. $tableExists = $database->first(
  10. "SELECT 1 AS tbl FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'customer'"
  11. );
  12. if ($tableExists) {
  13. return;
  14. }
  15. $database->execute(
  16. 'CREATE TABLE customer (
  17. id INT IDENTITY(1,1) NOT NULL,
  18. customer_type_id INT NOT NULL,
  19. attribute_values NVARCHAR(MAX) NULL,
  20. created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  21. updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  22. CONSTRAINT PK_customer PRIMARY KEY (id),
  23. CONSTRAINT FK_customer_customer_type FOREIGN KEY (customer_type_id)
  24. REFERENCES customer_type (id) ON UPDATE NO ACTION ON DELETE NO ACTION
  25. )'
  26. );
  27. $database->execute('CREATE INDEX IX_customer_customer_type_id ON customer (customer_type_id)');
  28. }
  29. public function down(Database $database): void
  30. {
  31. $database->execute('DROP TABLE IF EXISTS customer');
  32. }
  33. };

Powered by TurnKey Linux.