CREATE TABLE IF NOT EXISTS pessoa_fornecedores (id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,pessoa_id BIGINT UNSIGNED NOT NULL,empresa_id BIGINT UNSIGNED NOT NULL,grupo_pessoa_id BIGINT UNSIGNED NULL,prazo_entrega_dias INT NOT NULL DEFAULT 0,valor_minimo_pedido DECIMAL(15,2) NOT NULL DEFAULT 0,tipo_frete VARCHAR(10) NOT NULL DEFAULT 'cif',indicador_ie VARCHAR(20) NOT NULL DEFAULT 'contribuinte',optante_simples BOOLEAN NOT NULL DEFAULT FALSE,produtor_rural BOOLEAN NOT NULL DEFAULT FALSE,bloqueado BOOLEAN NOT NULL DEFAULT FALSE,motivo_bloqueio VARCHAR(500) NULL,ativo BOOLEAN NOT NULL DEFAULT TRUE,criado_em TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,atualizado_em TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,excluido_em TIMESTAMP NULL,CONSTRAINT fk_pessoa_fornecedores_pessoa FOREIGN KEY(pessoa_id) REFERENCES pessoas(id),CONSTRAINT fk_pessoa_fornecedores_empresa FOREIGN KEY(empresa_id) REFERENCES empresas(id),CONSTRAINT fk_pessoa_fornecedores_grupo FOREIGN KEY(grupo_pessoa_id) REFERENCES grupos_pessoa(id),UNIQUE KEY uq_pessoa_fornecedores(pessoa_id,empresa_id),INDEX idx_pessoa_fornecedores_empresa(empresa_id,ativo)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pessoa_dados_bancarios (id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,pessoa_id BIGINT UNSIGNED NOT NULL,banco_codigo VARCHAR(10),banco_nome VARCHAR(100),agencia VARCHAR(20),conta VARCHAR(30),tipo_conta VARCHAR(20),chave_pix VARCHAR(160),titular VARCHAR(160),documento_titular VARCHAR(14),principal BOOLEAN NOT NULL DEFAULT FALSE,CONSTRAINT fk_pessoa_dados_bancarios_pessoa FOREIGN KEY(pessoa_id) REFERENCES pessoas(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
