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 lines
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 = 'campaign'"
  11. );
  12. if ($tableExists) {
  13. return;
  14. }
  15. $database->execute(
  16. 'CREATE TABLE campaign (
  17. id INT IDENTITY(1,1) NOT NULL,
  18. campaign_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_campaign PRIMARY KEY (id),
  23. CONSTRAINT FK_campaign_campaign_type FOREIGN KEY (campaign_type_id)
  24. REFERENCES campaign_type (id)
  25. ON UPDATE NO ACTION
  26. ON DELETE NO ACTION
  27. )'
  28. );
  29. }
  30. public function down(Database $database): void
  31. {
  32. $database->execute('DROP TABLE IF EXISTS campaign');
  33. }
  34. };

Powered by TurnKey Linux.