/*
  Warnings:

  - You are about to drop the column `opensip_attrs` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_description` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_groupid` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_gwlist` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_prefix` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_priority` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_routeid` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_ruleid` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_sort_alg` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_sort_profile` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `opensip_timerec` on the `rules` table. All the data in the column will be lost.
  - You are about to drop the column `reference` on the `rules` table. All the data in the column will be lost.
  - Added the required column `rulegroupd_id` to the `rules` table without a default value. This is not possible if the table is not empty.
  - Added the required column `title` to the `rules` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE `dial-plan-group` DROP FOREIGN KEY `dial-plan-group_rule_id_fkey`;

-- DropForeignKey
ALTER TABLE `tariffs` DROP FOREIGN KEY `tariffs_rule_id_fkey`;

-- DropIndex
DROP INDEX `dial-plan-group_rule_id_fkey` ON `dial-plan-group`;

-- DropIndex
DROP INDEX `tariffs_rule_id_fkey` ON `tariffs`;

-- AlterTable
ALTER TABLE `rules` DROP COLUMN `opensip_attrs`,
    DROP COLUMN `opensip_description`,
    DROP COLUMN `opensip_groupid`,
    DROP COLUMN `opensip_gwlist`,
    DROP COLUMN `opensip_prefix`,
    DROP COLUMN `opensip_priority`,
    DROP COLUMN `opensip_routeid`,
    DROP COLUMN `opensip_ruleid`,
    DROP COLUMN `opensip_sort_alg`,
    DROP COLUMN `opensip_sort_profile`,
    DROP COLUMN `opensip_timerec`,
    DROP COLUMN `reference`,
    ADD COLUMN `rulegroupd_id` INTEGER NOT NULL,
    ADD COLUMN `title` VARCHAR(191) NOT NULL;

-- CreateTable
CREATE TABLE `rule_groups` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `opensip_ruleid` INTEGER NULL,
    `opensip_groupid` VARCHAR(191) NOT NULL,
    `opensip_prefix` VARCHAR(191) NOT NULL,
    `opensip_timerec` VARCHAR(191) NULL,
    `opensip_priority` INTEGER NOT NULL DEFAULT 0,
    `opensip_routeid` VARCHAR(191) NULL,
    `opensip_gwlist` VARCHAR(191) NULL,
    `opensip_sort_alg` VARCHAR(191) NOT NULL DEFAULT 'N',
    `opensip_sort_profile` INTEGER NULL,
    `opensip_attrs` VARCHAR(191) NULL,
    `opensip_description` VARCHAR(191) NULL,
    `reference` VARCHAR(191) NULL,
    `arquived` BOOLEAN NOT NULL DEFAULT false,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `last_modified` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `tariffs` ADD CONSTRAINT `tariffs_rule_id_fkey` FOREIGN KEY (`rule_id`) REFERENCES `rule_groups`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `rules` ADD CONSTRAINT `rules_rulegroupd_id_fkey` FOREIGN KEY (`rulegroupd_id`) REFERENCES `rule_groups`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `dial-plan-group` ADD CONSTRAINT `dial-plan-group_rule_id_fkey` FOREIGN KEY (`rule_id`) REFERENCES `rule_groups`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
