База данных

Предпросмотр схемы

Эта страница показывает, как типизированный PHP schema blueprint преобразуется в SQL согласно активной грамматике базы данных. Команды над базой данных не выполняются.

Режим
create
Таблица
_tmp_schema_demo_article
Статус
Предпросмотр готов
Preview only. No SQL was executed.

PHP blueprint

Вход
schema.php
$schema->create('_tmp_schema_demo_article', static function (TableBlueprint $table): void {
    $table->engine('InnoDB');
    $table->charset('utf8mb4');
    $table->collation('utf8mb4_unicode_ci');
    $table->comment('Demo article table generated by Schema preview.');

    $table->id('article_id')
        ->comment('Primary article identifier.');

    $table->string('title', 255)
        ->comment('Public article title.');

    $table->string('slug', 255)
        ->unique()
        ->comment('SEO friendly unique article URL slug.');

    $table->integer('article_status')
        ->default(1)
        ->comment('Article status flag. 1 = published, 0 = hidden.');

    $table->datetime('created_at')
        ->nullable()
        ->comment('Creation timestamp.');

    $table->datetime('updated_at')
        ->nullable()
        ->comment('Last update timestamp.');

    $table->index('article_status');
}, ifNotExists: true);

Сгенерированный SQL

Выход
statement-1.sql
CREATE TABLE IF NOT EXISTS `_tmp_schema_demo_article` (
	`article_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Primary article identifier.',
	`title` VARCHAR(255) NOT NULL COMMENT 'Public article title.',
	`slug` VARCHAR(255) NOT NULL COMMENT 'SEO friendly unique article URL slug.',
	`article_status` INT NOT NULL DEFAULT 1 COMMENT 'Article status flag. 1 = published, 0 = hidden.',
	`created_at` DATETIME NULL COMMENT 'Creation timestamp.',
	`updated_at` DATETIME NULL COMMENT 'Last update timestamp.',
	PRIMARY KEY (`article_id`),
	UNIQUE KEY `unique_slug` (`slug`),
	KEY `index_article_status` (`article_status`)
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'Demo article table generated by Schema preview.'