{
  "scenarios": [
    {
      "type": "create",
      "name": "Create Table For RLS policy",
      "endpoint": "NODE-table.obj",
      "sql_endpoint": "NODE-table.sql_id",
      "data": {
        "name": "test_rls_policy",
        "columns": [
          {
            "name": "emp_id",
            "cltype": "integer",
            "is_primary_key": true
          },
          {
            "name": "name",
            "cltype": "text"
          },
          {
            "name": "salary",
            "cltype": "bigint"
          }
        ],
        "is_partitioned": false,
        "schema": "public",
        "spcname": "pg_default"
      },
      "store_object_id": true
    },
    {
      "type": "create",
      "name": "Create Role to test multiple role for RLS policy",
      "endpoint": "NODE-role.obj",
      "sql_endpoint": "NODE-role.sql_id",
      "data": {
        "rolname": "Role_1",
        "rolcanlogin": false,
        "rolpassword": null,
        "rolconnlimit": -1,
        "rolsuper": false,
        "rolcreaterole": false,
        "rolcreatedb": false,
        "rolinherit": true,
        "rolreplication": false,
        "rolmembership": [],
        "seclabels": [],
        "variables": []
      },
      "store_object_id": true
    },
    {
      "type": "create",
      "name": "Create Role to test multiple role for RLS policy",
      "endpoint": "NODE-role.obj",
      "sql_endpoint": "NODE-role.sql_id",
      "data": {
        "rolname": "role_2",
        "rolcanlogin": false,
        "rolpassword": null,
        "rolconnlimit": -1,
        "rolsuper": false,
        "rolcreaterole": false,
        "rolcreatedb": false,
        "rolinherit": true,
        "rolreplication": false,
        "rolmembership": [],
        "seclabels": [],
        "variables": []
      },
      "store_object_id": true
    },
    {
      "type": "create",
      "name": "Create simple select event RLS policy",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql",
      "data": {
        "name": "test_select_policy_rls_$%{}[]()&*^!@\"'`\\/#",
        "event": "SELECT",
        "policyowner": ["public"],
        "schema": "public",
        "type": "PERMISSIVE",
        "description": "This is test description"
      },
      "expected_sql_file": "create_select_policy.sql",
      "expected_msql_file": "create_select_policy_msql.sql"
    },
    {
      "type": "alter",
      "name": "Alter simple select event RLS policy with using clause",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "name": "test_select_policy_rls_$%{}[]()&*^!@\"'`\\/#",
        "using": "name = current_user",
        "schema": "public"
      },
      "expected_sql_file": "alter_select_policy.sql",
      "expected_msql_file": "alter_select_policy_msql.sql"
    },
    {
      "type": "delete",
      "name": "Drop policy",
      "endpoint": "NODE-row_security_policy.delete_id",
      "data": {
        "name": "test_select_rls_policy_$%{}[]()&*^!@\"'`\\/#"
      }
    },
    {
      "type": "create",
      "name": "Create simple insert event RLS policy",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql",
      "data": {
        "name": "test_simple_insert_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "policyowner": ["public"],
        "event": "INSERT",
        "withcheck": "",
        "type": "PERMISSIVE",
        "schema": "public"
      },
      "expected_sql_file": "create_simple_insert_policy.sql",
      "expected_msql_file": "create_simple_insert_policy_msql.sql"
    },
    {
      "type": "alter",
      "name": "Alter simple insert event RLS policy by adding check",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "name": "test_simple_insert_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "withcheck": "current_user = name",
        "schema": "public"
      },
      "expected_sql_file": "alter_simple_insert_policy.sql",
      "expected_msql_file": "alter_simple_insert_policy_msql.sql"
    },
    {
      "type": "delete",
      "name": "Drop policy",
      "endpoint": "NODE-row_security_policy.delete_id",
      "data": {
        "name": "test_simple_insert_rls_policy_$%{}[]()&*^!@\"'`\\/#"
      }
    },
    {
      "type": "create",
      "name": "Create update event restrictive RLS policy with check and using clause",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql",
      "data": {
        "name": "test_update_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "policyowner": ["public"],
        "event": "UPDATE",
        "using": "true",
        "withcheck": "name != null",
        "type": "RESTRICTIVE",
        "schema": "public"
      },
      "expected_sql_file": "create_update_policy_with_check_and_using.sql",
      "expected_msql_file": "create_update_policy_with_check_and_using_msql.sql"
    },
    {
      "type": "alter",
      "name": "Alter update event restrictive RLS policy with check and using clause",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "name": "test_update_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "withcheck": "emp_id != 0",
        "using": "current_user=name"
      },
      "expected_sql_file": "alter_update_policy_with_check_and_using.sql",
      "expected_msql_file": "alter_update_policy_with_check_and_using_msql.sql"
    },
    {
      "type": "delete",
      "name": "Drop policy",
      "endpoint": "NODE-row_security_policy.delete_id",
      "data": {
        "name": "test_update_rls_policy_$%{}[]()&*^!@\"'`\\/#"
      }
    },
    {
      "type": "create",
      "name": "Create delete event restrictive RLS policy with check",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql",
      "data": {
        "name": "test_delete_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "policyowner": ["public"],
        "event": "DELETE",
        "using": "current_user = name",
        "withcheck": "",
        "type": "RESTRICTIVE",
        "schema": "public"
      },
      "expected_sql_file": "create_delete_policy_with_using.sql",
      "expected_msql_file": "create_delete_policy_with_using_msql.sql"
    },
    {
      "type": "alter",
      "name": "Alter delete event restrictive RLS policy by changing check clause",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "name": "test_delete_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "using": "salary < 1000000000000",
        "schema": "public"
      },
      "expected_sql_file": "alter_delete_policy_with_using.sql",
      "expected_msql_file": "alter_delete_policy_with_using_msql.sql"
    },
    {
      "type": "delete",
      "name": "Drop policy",
      "endpoint": "NODE-row_security_policy.delete_id",
      "data": {
        "name": "test_delete_rls_policy_update_name_$%{}[]()&*^!@\"'`\\/#"
      }
    },
    {
      "type": "create",
      "name": "Create simple all event restrictive RLS policy",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql",
      "data": {
        "name": "test_all_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "policyowner": ["public"],
        "event": "ALL",
        "type": "RESTRICTIVE",
        "schema": "public"
      },
      "expected_sql_file": "create_simple_all_policy.sql",
      "expected_msql_file": "create_simple_all_policy_msql.sql"
    },
    {
      "type": "alter",
      "name": "Alter simple all event restrictive RLS policy with using & check clause",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "name": "test_all_rls_policy_$%{}[]()&*^!@\"'`\\/#",
        "using": "true",
        "withcheck": "true",
        "schema": "public"
      },
      "expected_sql_file": "alter_simple_all_policy.sql",
      "expected_msql_file": "alter_simple_all_policy_msql.sql"
    },
    {
      "type": "delete",
      "name": "Drop policy",
      "endpoint": "NODE-row_security_policy.delete_id",
      "data": {
        "name": "test_all_rls_policy_$%{}[]()&*^!@\"'`\\/#"
      }
    },
    {
      "type": "create",
      "name": "Create RLS policy",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "data": {
        "name": "test",
        "schema": "public"
      },
      "expected_sql_file": "create_public_policy.sql"
    },
    {
      "type": "alter",
      "name": "Alter policy name",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "name": "policy_1"
      },
      "expected_sql_file": "alter_policy.sql",
      "expected_msql_file": "alter_policy_msql.sql"
    },
    {
      "type": "create",
      "name": "Create RLS policy for event 'ALL'",
      "endpoint": "NODE-row_security_policy.obj",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "data": {
        "name": "all_event_policy",
        "event": "ALL",
        "policyowner": ["Role_1", "role_2"],
        "schema": "public",
        "using": "true",
        "withcheck": "true",
        "type": "RESTRICTIVE"
      },
      "expected_sql_file": "create_all_event_policy.sql"
    },
    {
      "type": "alter",
      "name": "Alter policy owner",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "policyowner": ["role_2"]
      },
      "expected_sql_file": "alter_owner_policy.sql",
      "expected_msql_file": "alter_owner_policy_msql.sql"
    },
    {
      "type": "alter",
      "name": "Alter policy owner remove all users",
      "endpoint": "NODE-row_security_policy.obj_id",
      "sql_endpoint": "NODE-row_security_policy.sql_id",
      "msql_endpoint": "NODE-row_security_policy.msql_id",
      "data": {
        "policyowner": []
      },
      "expected_sql_file": "alter_remove_all_owner_policy.sql",
      "expected_msql_file": "alter_remove_all_owner_policy_msql.sql"
    },
    {
      "type": "delete",
      "name": "Drop policy",
      "endpoint": "NODE-row_security_policy.delete_id",
      "data": {
        "name": "test_delete_policy_$%{}[]()&*^!@\"'`\\/#"
      }
    },
    {
      "type": "delete",
      "name": "Drop Role",
      "endpoint": "NODE-role.obj",
      "data": {"ids": ["<Role_1>", "<role_2>"]},
      "preprocess_data": true
    }
  ]
}
