Newer
Older
smart-home-server / server / migrations / 20250602_000000_create_sessions_table.php
<?php

use SHServ\Migrations\Migration;

/**
 * Migration: create_sessions_table
 */
class CreateSessionsTable extends Migration {

	public function up(): void {
		$this->tb()->create_table('sessions', [
			'id' => [
				'type' => 'INT',
				'length' => 11,
				'auto_increment' => true,
				'can_be_null' => false,
			],
			'uid' => [
				'type' => 'INT',
				'length' => 11,
				'default' => 0,
				'can_be_null' => false,
			],
			'status' => [
				'type' => 'VARCHAR',
				'length' => 50,
				'default' => 'active',
				'can_be_null' => false,
			],
			'token' => [
				'type' => 'VARCHAR',
				'length' => 255,
				'can_be_null' => false,
			],
			'last_using_at' => [
				'type' => 'DATETIME',
				'default' => 'NULL',
				'can_be_null' => true,
			],
			'update_at' => [
				'type' => 'DATETIME',
				'default' => 'NULL',
				'can_be_null' => true,
			],
			'create_at' => [
				'type' => 'DATETIME',
				'default' => 'CURRENT_TIMESTAMP',
				'can_be_null' => false,
			],
		], 'id', 'InnoDB');
	}

	public function down(): void {
		$this->drop_table_if_exists('sessions');
	}
}