quinta-feira, 9 de janeiro de 2020

cidadao2020

-- phpMyAdmin SQL Dump
-- version 4.7.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: 09-Jan-2020 às 14:08
-- Versão do servidor: 5.6.34
-- PHP Version: 7.1.11

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";

--
-- Database: `cidadao2020`
--

-- --------------------------------------------------------

--
-- Estrutura da tabela `atributospessoais`
--

CREATE TABLE `atributospessoais` (
  `id` int(11) NOT NULL,
  `atributo` varchar(100) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1',
  `idAdmin` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `balcoes`
--

CREATE TABLE `balcoes` (
  `id` int(11) NOT NULL,
  `balcao` varchar(100) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `balcoes`
--

INSERT INTO `balcoes` (`id`, `balcao`, `estado`) VALUES
(1, 'A', 1),
(2, 'B', 1),
(3, 'C', 1),
(4, 'D', 1),
(5, 'E', 1),
(6, 'F', 1);

-- --------------------------------------------------------

--
-- Estrutura da tabela `entidades`
--

CREATE TABLE `entidades` (
  `id` int(11) NOT NULL,
  `entidade` varchar(100) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `entidades`
--

INSERT INTO `entidades` (`id`, `entidade`, `estado`) VALUES
(1, 'EDP', 1),
(2, 'VODAFONE', 1),
(3, 'MEO', 1),
(4, 'GALP', 0);

-- --------------------------------------------------------

--
-- Estrutura da tabela `entidades_servicos`
--

CREATE TABLE `entidades_servicos` (
  `id` int(11) NOT NULL,
  `idEntidade` int(11) NOT NULL,
  `idServico` int(11) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `entidades_servicos`
--

INSERT INTO `entidades_servicos` (`id`, `idEntidade`, `idServico`, `estado`) VALUES
(1, 1, 1, 1),
(2, 1, 2, 1),
(3, 1, 3, 0),
(4, 4, 2, 1),
(5, 3, 2, 1);

-- --------------------------------------------------------

--
-- Estrutura da tabela `entidades_servicos_users`
--

CREATE TABLE `entidades_servicos_users` (
  `id` int(11) NOT NULL,
  `idEntidadeServico` int(11) NOT NULL,
  `idUser` int(11) NOT NULL,
  `idAdmin` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `entidades_servicos_users`
--

INSERT INTO `entidades_servicos_users` (`id`, `idEntidadeServico`, `idUser`, `idAdmin`, `dataReg`, `estado`) VALUES
(1, 2, 3, 1, '2020-01-07 09:04:53', 1),
(2, 4, 3, 1, '2020-01-07 09:16:16', 1),
(3, 5, 3, 1, '2020-01-07 09:16:16', 1);

-- --------------------------------------------------------

--
-- Estrutura da tabela `estados_das_senhas`
--

CREATE TABLE `estados_das_senhas` (
  `id` int(11) NOT NULL,
  `estadoDaSenha` varchar(100) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `estados_login`
--

CREATE TABLE `estados_login` (
  `id` int(11) NOT NULL,
  `idLogin` int(11) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1',
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `estados_login`
--

INSERT INTO `estados_login` (`id`, `idLogin`, `estado`, `dataReg`) VALUES
(1, 1, 1, '2020-01-07 09:53:34'),
(2, 1, 0, '2020-01-07 09:58:02'),
(3, 1, 1, '2020-01-07 11:25:52'),
(4, 1, 0, '2020-01-07 11:30:54'),
(5, 1, 2, '2020-01-07 11:31:18'),
(6, 1, 3, '2020-01-07 11:31:44'),
(7, 1, 1, '2020-01-07 11:40:42');

-- --------------------------------------------------------

--
-- Estrutura da tabela `intervencoes`
--

CREATE TABLE `intervencoes` (
  `id` int(11) NOT NULL,
  `idUser` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `estado` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `intervencoes`
--

INSERT INTO `intervencoes` (`id`, `idUser`, `dataReg`, `estado`) VALUES
(1, 1, '2019-12-05 16:26:14', 0),
(2, 1, '2019-12-10 11:52:27', 1),
(3, 1, '2019-12-10 11:52:28', 0),
(4, 1, '2019-12-10 11:52:30', 1),
(5, 1, '2019-12-10 11:52:31', 0),
(6, 1, '2019-12-10 12:07:04', 1);

-- --------------------------------------------------------

--
-- Estrutura da tabela `logins`
--

CREATE TABLE `logins` (
  `id` int(11) NOT NULL,
  `idUser` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `logins`
--

INSERT INTO `logins` (`id`, `idUser`, `dataReg`) VALUES
(1, 3, '2020-01-07 09:50:47');

-- --------------------------------------------------------

--
-- Estrutura da tabela `passwords`
--

CREATE TABLE `passwords` (
  `id` int(11) NOT NULL,
  `pass` varchar(100) NOT NULL,
  `idUser` int(11) NOT NULL,
  `estadoReg` tinyint(1) NOT NULL DEFAULT '1',
  `dataReg` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `passwords`
--

INSERT INTO `passwords` (`id`, `pass`, `idUser`, `estadoReg`, `dataReg`) VALUES
(1, '123', 1, 1, '2019-11-19 15:24:26'),
(2, '321', 1, 1, '2019-11-19 15:24:26'),
(3, '987', 2, 1, '2019-11-19 15:24:56'),
(4, '654', 3, 1, '2019-11-19 15:24:56'),
(5, '765', 3, 1, '2019-11-19 15:28:37'),
(6, '991', 1, 1, '2019-11-19 15:28:37'),
(7, '0000', 2, 1, '2019-11-19 15:44:55');

-- --------------------------------------------------------

--
-- Estrutura da tabela `pessoas`
--

CREATE TABLE `pessoas` (
  `id` int(11) NOT NULL,
  `firstName` varchar(100) DEFAULT NULL,
  `lastName` varchar(100) DEFAULT NULL,
  `birthday` date NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `estado` tinyint(1) NOT NULL DEFAULT '1',
  `idAdmin` int(11) NOT NULL COMMENT 'id da pessoa que está a inserir na tabela'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `pessoas_atributospessoais`
--

CREATE TABLE `pessoas_atributospessoais` (
  `id` int(11) NOT NULL,
  `idPessoa` int(11) NOT NULL,
  `idAtributoPessoal` int(11) NOT NULL,
  `valor` varchar(200) NOT NULL,
  `idAdmin` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `privilegios`
--

CREATE TABLE `privilegios` (
  `id` int(11) NOT NULL,
  `privilegio` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `privilegios`
--

INSERT INTO `privilegios` (`id`, `privilegio`) VALUES
(1, 'admin'),
(2, 'geral'),
(3, 'client'),
(4, 'public');

-- --------------------------------------------------------

--
-- Estrutura da tabela `senhas`
--

CREATE TABLE `senhas` (
  `id` int(11) NOT NULL,
  `idEntidadeServico` int(11) NOT NULL,
  `prioridade` tinyint(1) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `servicos`
--

CREATE TABLE `servicos` (
  `id` int(11) NOT NULL,
  `servico` varchar(100) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `servicos`
--

INSERT INTO `servicos` (`id`, `servico`, `estado`) VALUES
(1, 'Informações', 1),
(2, 'Pagamentos', 1),
(3, 'Contratos', 1),
(4, 'Entregas', 0);

-- --------------------------------------------------------

--
-- Estrutura da tabela `sessoes`
--

CREATE TABLE `sessoes` (
  `id` int(11) NOT NULL,
  `idLogin` int(11) NOT NULL,
  `idEntidadeServico` int(11) NOT NULL,
  `idBalcao` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `estado` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `sessoes`
--

INSERT INTO `sessoes` (`id`, `idLogin`, `idEntidadeServico`, `idBalcao`, `dataReg`, `estado`) VALUES
(1, 1, 2, 1, '2020-01-07 12:04:31', 1),
(2, 1, 4, 1, '2020-01-07 12:04:31', 1);

-- --------------------------------------------------------

--
-- Estrutura da tabela `sessoes_senhas_estados`
--

CREATE TABLE `sessoes_senhas_estados` (
  `id` int(11) NOT NULL,
  `idSessao` int(11) NOT NULL,
  `idSenha` int(11) NOT NULL,
  `idEstadoDaSenha` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(100) NOT NULL,
  `estadoReg` tinyint(1) NOT NULL DEFAULT '0',
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `users`
--

INSERT INTO `users` (`id`, `username`, `estadoReg`, `dataReg`) VALUES
(1, 'mloureiro', 0, '2019-11-19 15:09:27'),
(2, 'diogo', 0, '2019-11-19 15:09:27'),
(3, 'ana', 0, '2019-11-19 15:09:36');

-- --------------------------------------------------------

--
-- Estrutura da tabela `users_pessoas`
--

CREATE TABLE `users_pessoas` (
  `id` int(11) NOT NULL,
  `idUser` int(11) NOT NULL,
  `idPessoa` int(11) NOT NULL,
  `estado` tinyint(1) NOT NULL DEFAULT '1',
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `idAdmin` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Estrutura da tabela `users_privilegios`
--

CREATE TABLE `users_privilegios` (
  `id` int(11) NOT NULL,
  `idUser` int(11) NOT NULL,
  `idPrivilegio` int(11) NOT NULL,
  `dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `estado` tinyint(1) NOT NULL DEFAULT '1',
  `idAdmin` int(11) NOT NULL COMMENT 'O utilizador que está a operar a base de dados!'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Extraindo dados da tabela `users_privilegios`
--

INSERT INTO `users_privilegios` (`id`, `idUser`, `idPrivilegio`, `dataReg`, `estado`, `idAdmin`) VALUES
(1, 1, 1, '2019-11-27 15:12:21', 1, 1),
(2, 1, 2, '2019-11-27 15:12:21', 1, 1),
(3, 2, 1, '2019-11-27 15:16:04', 1, 1),
(4, 3, 2, '2019-11-27 15:16:04', 1, 1);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v1_admin`
-- (See below for the actual view)
--
CREATE TABLE `v1_admin` (
`username` varchar(100)
,`privilegio` varchar(100)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v1_entidades_servicos_full`
-- (See below for the actual view)
--
CREATE TABLE `v1_entidades_servicos_full` (
`idEntidadeServico` int(11)
,`idEntidade` int(11)
,`entidade` varchar(100)
,`estadoEntidade` tinyint(1)
,`idServico` int(11)
,`servico` varchar(100)
,`estadoServico` tinyint(1)
,`estadoEntidadeServico` tinyint(1)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v1_estados_login`
-- (See below for the actual view)
--
CREATE TABLE `v1_estados_login` (
`id` int(11)
,`idLogin` int(11)
,`estado` tinyint(1)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v1_estado_do_cidadao2020`
-- (See below for the actual view)
--
CREATE TABLE `v1_estado_do_cidadao2020` (
`estado` tinyint(1)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v1_passwords`
-- (See below for the actual view)
--
CREATE TABLE `v1_passwords` (
`id` int(11)
,`idUser` int(11)
,`pass` varchar(100)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v2_entidades_servicos_users`
-- (See below for the actual view)
--
CREATE TABLE `v2_entidades_servicos_users` (
`idUser` int(11)
,`username` varchar(100)
,`idEntidadeServico` int(11)
,`entidade` varchar(100)
,`servico` varchar(100)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v2_login_atual`
-- (See below for the actual view)
--
CREATE TABLE `v2_login_atual` (
`idUser` int(11)
,`username` varchar(100)
,`idLogin` int(11)
,`estadoLogin` tinyint(1)
,`estado` varchar(12)
);

-- --------------------------------------------------------

--
-- Stand-in structure for view `v2_users_passwords`
-- (See below for the actual view)
--
CREATE TABLE `v2_users_passwords` (
`idUser` int(11)
,`username` varchar(100)
,`estadoReg` tinyint(1)
,`pass` varchar(100)
);

-- --------------------------------------------------------

--
-- Structure for view `v1_admin`
--
DROP TABLE IF EXISTS `v1_admin`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1_admin`  AS  select `users`.`username` AS `username`,`privilegios`.`privilegio` AS `privilegio` from ((`users` join `privilegios`) join `users_privilegios`) where ((`users`.`id` = `users_privilegios`.`idUser`) and (`privilegios`.`id` = `users_privilegios`.`idPrivilegio`) and (`users_privilegios`.`idPrivilegio` = 1)) ;

-- --------------------------------------------------------

--
-- Structure for view `v1_entidades_servicos_full`
--
DROP TABLE IF EXISTS `v1_entidades_servicos_full`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1_entidades_servicos_full`  AS  select `entidades_servicos`.`id` AS `idEntidadeServico`,`entidades_servicos`.`idEntidade` AS `idEntidade`,`entidades`.`entidade` AS `entidade`,`entidades`.`estado` AS `estadoEntidade`,`entidades_servicos`.`idServico` AS `idServico`,`servicos`.`servico` AS `servico`,`servicos`.`estado` AS `estadoServico`,`entidades_servicos`.`estado` AS `estadoEntidadeServico` from ((`entidades` join `entidades_servicos`) join `servicos`) where ((`entidades`.`id` = `entidades_servicos`.`idEntidade`) and (`servicos`.`id` = `entidades_servicos`.`idServico`)) ;

-- --------------------------------------------------------

--
-- Structure for view `v1_estados_login`
--
DROP TABLE IF EXISTS `v1_estados_login`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1_estados_login`  AS  select `estados_login`.`id` AS `id`,`estados_login`.`idLogin` AS `idLogin`,`estados_login`.`estado` AS `estado` from `estados_login` where `estados_login`.`id` in (select max(`estados_login`.`id`) from `estados_login` group by `estados_login`.`idLogin`) ;

-- --------------------------------------------------------

--
-- Structure for view `v1_estado_do_cidadao2020`
--
DROP TABLE IF EXISTS `v1_estado_do_cidadao2020`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1_estado_do_cidadao2020`  AS  select `intervencoes`.`estado` AS `estado` from `intervencoes` where `intervencoes`.`id` in (select max(`intervencoes`.`id`) from `intervencoes`) ;

-- --------------------------------------------------------

--
-- Structure for view `v1_passwords`
--
DROP TABLE IF EXISTS `v1_passwords`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1_passwords`  AS  select `passwords`.`id` AS `id`,`passwords`.`idUser` AS `idUser`,`passwords`.`pass` AS `pass` from `passwords` where `passwords`.`id` in (select max(`passwords`.`id`) from `passwords` group by `passwords`.`idUser`) ;

-- --------------------------------------------------------

--
-- Structure for view `v2_entidades_servicos_users`
--
DROP TABLE IF EXISTS `v2_entidades_servicos_users`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2_entidades_servicos_users`  AS  select `entidades_servicos_users`.`idUser` AS `idUser`,`users`.`username` AS `username`,`entidades_servicos_users`.`idEntidadeServico` AS `idEntidadeServico`,`v1_entidades_servicos_full`.`entidade` AS `entidade`,`v1_entidades_servicos_full`.`servico` AS `servico` from ((`users` join `entidades_servicos_users`) join `v1_entidades_servicos_full`) where ((`users`.`id` = `entidades_servicos_users`.`idUser`) and (`entidades_servicos_users`.`idEntidadeServico` = `v1_entidades_servicos_full`.`idEntidadeServico`)) ;

-- --------------------------------------------------------

--
-- Structure for view `v2_login_atual`
--
DROP TABLE IF EXISTS `v2_login_atual`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2_login_atual`  AS  select `logins`.`idUser` AS `idUser`,`users`.`username` AS `username`,`v1_estados_login`.`idLogin` AS `idLogin`,`v1_estados_login`.`estado` AS `estadoLogin`,(case when (`v1_estados_login`.`estado` = 0) then 'Inativo' when (`v1_estados_login`.`estado` = 1) then 'Ativo' when (`v1_estados_login`.`estado` = 2) then 'Suspenso' else 'Outro estado' end) AS `estado` from ((`users` join `logins`) join `v1_estados_login`) where ((`users`.`id` = `logins`.`idUser`) and (`logins`.`id` = `v1_estados_login`.`idLogin`)) ;

-- --------------------------------------------------------

--
-- Structure for view `v2_users_passwords`
--
DROP TABLE IF EXISTS `v2_users_passwords`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2_users_passwords`  AS  select `v1_passwords`.`idUser` AS `idUser`,`users`.`username` AS `username`,`users`.`estadoReg` AS `estadoReg`,`v1_passwords`.`pass` AS `pass` from (`users` join `v1_passwords`) where (`users`.`id` = `v1_passwords`.`idUser`) ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `atributospessoais`
--
ALTER TABLE `atributospessoais`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idAdmin` (`idAdmin`);

--
-- Indexes for table `balcoes`
--
ALTER TABLE `balcoes`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `entidades`
--
ALTER TABLE `entidades`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `entidades_servicos`
--
ALTER TABLE `entidades_servicos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idEntidade` (`idEntidade`),
  ADD KEY `idServico` (`idServico`);

--
-- Indexes for table `entidades_servicos_users`
--
ALTER TABLE `entidades_servicos_users`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idUser` (`idUser`),
  ADD KEY `idAdmin` (`idAdmin`),
  ADD KEY `idEntidadeServico` (`idEntidadeServico`);

--
-- Indexes for table `estados_das_senhas`
--
ALTER TABLE `estados_das_senhas`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `estados_login`
--
ALTER TABLE `estados_login`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idLogin` (`idLogin`);

--
-- Indexes for table `intervencoes`
--
ALTER TABLE `intervencoes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idUser` (`idUser`);

--
-- Indexes for table `logins`
--
ALTER TABLE `logins`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idUser` (`idUser`);

--
-- Indexes for table `passwords`
--
ALTER TABLE `passwords`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idUser` (`idUser`);

--
-- Indexes for table `pessoas`
--
ALTER TABLE `pessoas`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idAdmin` (`idAdmin`);

--
-- Indexes for table `pessoas_atributospessoais`
--
ALTER TABLE `pessoas_atributospessoais`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idPessoa` (`idPessoa`),
  ADD KEY `idAdmin` (`idAdmin`),
  ADD KEY `idAtributoPessoal` (`idAtributoPessoal`);

--
-- Indexes for table `privilegios`
--
ALTER TABLE `privilegios`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `senhas`
--
ALTER TABLE `senhas`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idEntidadeServico` (`idEntidadeServico`);

--
-- Indexes for table `servicos`
--
ALTER TABLE `servicos`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `sessoes`
--
ALTER TABLE `sessoes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idLogin` (`idLogin`),
  ADD KEY `idEntidadeServico` (`idEntidadeServico`),
  ADD KEY `idBalcao` (`idBalcao`);

--
-- Indexes for table `sessoes_senhas_estados`
--
ALTER TABLE `sessoes_senhas_estados`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idSessao` (`idSessao`),
  ADD KEY `idSenha` (`idSenha`),
  ADD KEY `idEstado` (`idEstadoDaSenha`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users_pessoas`
--
ALTER TABLE `users_pessoas`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idAdmin` (`idAdmin`),
  ADD KEY `idUser` (`idUser`),
  ADD KEY `idPessoa` (`idPessoa`);

--
-- Indexes for table `users_privilegios`
--
ALTER TABLE `users_privilegios`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idUser` (`idUser`),
  ADD KEY `idPrivilegio` (`idPrivilegio`),
  ADD KEY `idAdmin` (`idAdmin`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `atributospessoais`
--
ALTER TABLE `atributospessoais`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `balcoes`
--
ALTER TABLE `balcoes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT for table `entidades`
--
ALTER TABLE `entidades`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `entidades_servicos`
--
ALTER TABLE `entidades_servicos`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `entidades_servicos_users`
--
ALTER TABLE `entidades_servicos_users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `estados_das_senhas`
--
ALTER TABLE `estados_das_senhas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `estados_login`
--
ALTER TABLE `estados_login`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `intervencoes`
--
ALTER TABLE `intervencoes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT for table `logins`
--
ALTER TABLE `logins`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `passwords`
--
ALTER TABLE `passwords`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `pessoas`
--
ALTER TABLE `pessoas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `pessoas_atributospessoais`
--
ALTER TABLE `pessoas_atributospessoais`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `privilegios`
--
ALTER TABLE `privilegios`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `senhas`
--
ALTER TABLE `senhas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `servicos`
--
ALTER TABLE `servicos`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `sessoes`
--
ALTER TABLE `sessoes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `sessoes_senhas_estados`
--
ALTER TABLE `sessoes_senhas_estados`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `users_pessoas`
--
ALTER TABLE `users_pessoas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `users_privilegios`
--
ALTER TABLE `users_privilegios`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- Constraints for dumped tables
--

--
-- Limitadores para a tabela `atributospessoais`
--
ALTER TABLE `atributospessoais`
  ADD CONSTRAINT `atributospessoais_ibfk_1` FOREIGN KEY (`idAdmin`) REFERENCES `users` (`id`);

--
-- Limitadores para a tabela `entidades_servicos`
--
ALTER TABLE `entidades_servicos`
  ADD CONSTRAINT `entidades_servicos_ibfk_1` FOREIGN KEY (`idEntidade`) REFERENCES `entidades` (`id`),
  ADD CONSTRAINT `entidades_servicos_ibfk_2` FOREIGN KEY (`idServico`) REFERENCES `servicos` (`id`);

--
-- Limitadores para a tabela `entidades_servicos_users`
--
ALTER TABLE `entidades_servicos_users`
  ADD CONSTRAINT `entidades_servicos_users_ibfk_1` FOREIGN KEY (`idAdmin`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `entidades_servicos_users_ibfk_2` FOREIGN KEY (`idEntidadeServico`) REFERENCES `entidades_servicos` (`id`),
  ADD CONSTRAINT `entidades_servicos_users_ibfk_3` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`);

--
-- Limitadores para a tabela `estados_login`
--
ALTER TABLE `estados_login`
  ADD CONSTRAINT `estados_login_ibfk_1` FOREIGN KEY (`idLogin`) REFERENCES `logins` (`id`);

--
-- Limitadores para a tabela `intervencoes`
--
ALTER TABLE `intervencoes`
  ADD CONSTRAINT `intervencoes_ibfk_1` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`);

--
-- Limitadores para a tabela `logins`
--
ALTER TABLE `logins`
  ADD CONSTRAINT `logins_ibfk_1` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`);

--
-- Limitadores para a tabela `passwords`
--
ALTER TABLE `passwords`
  ADD CONSTRAINT `passwords_ibfk_1` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Limitadores para a tabela `pessoas`
--
ALTER TABLE `pessoas`
  ADD CONSTRAINT `pessoas_ibfk_1` FOREIGN KEY (`idAdmin`) REFERENCES `users` (`id`);

--
-- Limitadores para a tabela `pessoas_atributospessoais`
--
ALTER TABLE `pessoas_atributospessoais`
  ADD CONSTRAINT `pessoas_atributospessoais_ibfk_1` FOREIGN KEY (`idAdmin`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `pessoas_atributospessoais_ibfk_2` FOREIGN KEY (`idAtributoPessoal`) REFERENCES `atributospessoais` (`id`),
  ADD CONSTRAINT `pessoas_atributospessoais_ibfk_3` FOREIGN KEY (`idPessoa`) REFERENCES `pessoas` (`id`);

--
-- Limitadores para a tabela `senhas`
--
ALTER TABLE `senhas`
  ADD CONSTRAINT `senhas_ibfk_1` FOREIGN KEY (`idEntidadeServico`) REFERENCES `entidades_servicos` (`id`);

--
-- Limitadores para a tabela `sessoes`
--
ALTER TABLE `sessoes`
  ADD CONSTRAINT `sessoes_ibfk_1` FOREIGN KEY (`idBalcao`) REFERENCES `balcoes` (`id`),
  ADD CONSTRAINT `sessoes_ibfk_2` FOREIGN KEY (`idEntidadeServico`) REFERENCES `entidades_servicos` (`id`),
  ADD CONSTRAINT `sessoes_ibfk_3` FOREIGN KEY (`idLogin`) REFERENCES `logins` (`id`);

--
-- Limitadores para a tabela `sessoes_senhas_estados`
--
ALTER TABLE `sessoes_senhas_estados`
  ADD CONSTRAINT `sessoes_senhas_estados_ibfk_1` FOREIGN KEY (`idEstadoDaSenha`) REFERENCES `estados_das_senhas` (`id`),
  ADD CONSTRAINT `sessoes_senhas_estados_ibfk_2` FOREIGN KEY (`idSenha`) REFERENCES `senhas` (`id`),
  ADD CONSTRAINT `sessoes_senhas_estados_ibfk_3` FOREIGN KEY (`idSessao`) REFERENCES `sessoes` (`id`);

--
-- Limitadores para a tabela `users_pessoas`
--
ALTER TABLE `users_pessoas`
  ADD CONSTRAINT `users_pessoas_ibfk_1` FOREIGN KEY (`idAdmin`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `users_pessoas_ibfk_2` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `users_pessoas_ibfk_3` FOREIGN KEY (`idPessoa`) REFERENCES `pessoas` (`id`);

--
-- Limitadores para a tabela `users_privilegios`
--
ALTER TABLE `users_privilegios`
  ADD CONSTRAINT `users_privilegios_ibfk_1` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `users_privilegios_ibfk_2` FOREIGN KEY (`idAdmin`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `users_privilegios_ibfk_3` FOREIGN KEY (`idPrivilegio`) REFERENCES `privilegios` (`id`);
COMMIT;

Sem comentários:

Enviar um comentário