<?php

class Migration_20240712000009_create_custom_role_resources_tbl
{
    public static function up(PDO $pdo)
    {
        $sql = "
            CREATE TABLE IF NOT EXISTS custom_role_resources (
                role_id INT NOT NULL,
                resource_id INT NOT NULL,
                action_id INT NOT NULL,
                site_id INT NOT NULL,
                PRIMARY KEY(role_id, resource_id, action_id, site_id),
                FOREIGN KEY(role_id) REFERENCES roles(id),
                FOREIGN KEY(resource_id) REFERENCES resources(id),
                FOREIGN KEY(action_id) REFERENCES actions(id),
                FOREIGN KEY(site_id) REFERENCES properties(id)
            )
        ";

        $pdo->exec($sql);
    }

    public static function down(PDO $pdo)
    {
        $sql = "
            DROP TABLE IF EXISTS custom_role_resources;
        ";

        $pdo->exec($sql);
    }
}
