
    h	                     $    S SK Jr   " S S5      rg)   )get_db_connectionc                   $    \ rS rSr\S 5       rSrg)Role   c                     [        5       n U (       d  [        S5      e U R                  5       nSnUR                  U5        SnUR                  U5        SnUR                  U5        / SQnSnU H  nUR                  Xg45        M     SS/nS	n	U H  nUR                  X45        M     U R	                  5         U R                  5       (       a!  WR                  5         U R                  5         gg! [         a(  n
[        S
U
 35        U R                  5          Sn
A
NdSn
A
ff = f! U R                  5       (       a!  WR                  5         U R                  5         f f = f)zu
Ensures the roles and staff_roles tables exist and populates them with
default roles and initial staff assignments.
z2Could not connect to the database to set up roles.z
            CREATE TABLE IF NOT EXISTS `roles` (
                `id` INT AUTO_INCREMENT PRIMARY KEY,
                `name` VARCHAR(255) NOT NULL UNIQUE COMMENT 'The name of the role, e.g., Super Admin'
            ) ENGINE=InnoDB;
            aM  
            CREATE TABLE IF NOT EXISTS `staff_roles` (
                `pid` INT NOT NULL PRIMARY KEY COMMENT 'The staff member PID, acting as the unique identifier.',
                `role_id` INT NOT NULL,
                FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE CASCADE
            ) ENGINE=InnoDB;
            z
            INSERT INTO `roles` (`id`, `name`) VALUES
                (1, 'Super Admin'),
                (2, 'Admin'),
                (3, 'HR')
            ON DUPLICATE KEY UPDATE name=VALUES(name);
            )i
  iL  i  i9 zBINSERT IGNORE INTO `staff_roles` (`pid`, `role_id`) VALUES (%s, 1)i9 i  zBINSERT IGNORE INTO `staff_roles` (`pid`, `role_id`) VALUES (%s, 2)zError setting up roles tables: N)	r   	Exceptioncursorexecutecommitprintrollbackis_connectedclose)connr	   create_roles_tablecreate_staff_roles_tableinsert_rolessuper_admin_pidsinsert_super_adminspid
admin_pidsinsert_adminses              )/var/www/fran/franai/models/role_model.pycreate_tables_if_not_exists Role.create_tables_if_not_exists   sF    !"PQQ4	[[]F" NN-.($ NN34L NN<(  8"f'2F; ( !#J`M!}f5 " KKM   ""

 #	  	3A378MMOO	   ""

 #s*   BC0 0
D":DD% D""D% %8E N)__name__
__module____qualname____firstlineno__staticmethodr   __static_attributes__r       r   r   r      s    = =r$   r   N)services.mysql_servicer   r   r   r$   r   <module>r&      s    6? ?r$   