Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange formatted SQL #508

Closed
silvioprog opened this issue Feb 14, 2020 · 1 comment
Closed

Strange formatted SQL #508

silvioprog opened this issue Feb 14, 2020 · 1 comment
Assignees
Milestone

Comments

@silvioprog
Copy link

silvioprog commented Feb 14, 2020

Hi.

Please take a look at the following SQL formatted using vscode-sqltools (notice two spaces in front last CREATEs):

-- Tabela de contribuintes
CREATE TABLE IF NOT EXISTS fiscalidade_taxpayers (
  -- Identificador único
  id BIGSERIAL PRIMARY KEY,
  -- Nome
  name VARCHAR(200) NOT NULL UNIQUE,
  -- Razão Social
  business_name VARCHAR(200) NOT NULL UNIQUE,
  -- CNPJ
  registry VARCHAR(20) NOT NULL UNIQUE,
  -- E-mail
  email VARCHAR(100) NOT NULL UNIQUE,
  -- Certificado PKCS #12
  certificate TEXT NOT NULL,
  -- Senha do certificado
  certificate_password VARCHAR(100) NOT NULL,
  -- Token para login
  token VARCHAR(60) NOT NULL UNIQUE,
  -- Administrador
  manager BOOLEAN DEFAULT TRUE,
  -- Ativo
  active BOOLEAN NOT NULL DEFAULT TRUE,
  -- Data de cadastro
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
-- Insere usuário padrão (admin)
INSERT INTO fiscalidade_taxpayers (
    name,
    business_name,
    registry,
    email,
    certificate,
    certificate_password,
    token,
    manager
  )
VALUES
  (
    'admin',
    'Administrador',
    '',
    '',
    '',
    '',
    'yBtY7BaUiGIHMEXzs1UUdr',
    true
  );
-- Tabela de serviços
  CREATE TABLE IF NOT EXISTS fiscalidade_services (
    -- Identificador único
    id BIGSERIAL PRIMARY KEY,
    -- Descrição (NF-e, NFC-e etc.)
    description CHARACTER VARYING(50) NOT NULL UNIQUE,
    -- Serviço (nfe, nfce etc.)
    slug CHARACTER VARYING(50) NOT NULL UNIQUE,
    -- Ativo
    active BOOLEAN NOT NULL DEFAULT TRUE,
    -- Data de cadastro
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP
  );
-- Tabela para relacionar serviço a contribuinte
  CREATE TABLE IF NOT EXISTS fiscalidade_taxpayers_services (
    id BIGSERIAL PRIMARY KEY,
    -- ID do contribuinte
    taxpayer_id BIGINT NOT NULL REFERENCES fiscalidade_taxpayers (id) ON UPDATE CASCADE ON DELETE CASCADE,
    -- ID do serviço
    service_id BIGINT NOT NULL REFERENCES fiscalidade_services (id) ON UPDATE CASCADE ON DELETE CASCADE,
    -- Data de permissão
    allowed_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    -- Data de cadastro
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    UNIQUE (taxpayer_id, service_id)
  );
-- Insere serviços disponíveis.
INSERT INTO fiscalidade_services (description, slug)
VALUES
  ('NF-e', 'nfe');

It should be formatted as following:

-- Tabela de contribuintes
CREATE TABLE IF NOT EXISTS fiscalidade_taxpayers (
  -- Identificador único
  id BIGSERIAL PRIMARY KEY,
  -- Nome
  name VARCHAR(200) NOT NULL UNIQUE,
  -- Razão Social
  business_name VARCHAR(200) NOT NULL UNIQUE,
  -- CNPJ
  registry VARCHAR(20) NOT NULL UNIQUE,
  -- E-mail
  email VARCHAR(100) NOT NULL UNIQUE,
  -- Certificado PKCS #12
  certificate TEXT NOT NULL,
  -- Senha do certificado
  certificate_password VARCHAR(100) NOT NULL,
  -- Token para login
  token VARCHAR(60) NOT NULL UNIQUE,
  -- Administrador
  manager BOOLEAN DEFAULT TRUE,
  -- Ativo
  active BOOLEAN NOT NULL DEFAULT TRUE,
  -- Data de cadastro
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- Insere usuário padrão (admin)
INSERT INTO fiscalidade_taxpayers (
    name,
    business_name,
    registry,
    email,
    certificate,
    certificate_password,
    token,
    manager
  )
VALUES
  (
    'admin',
    'Administrador',
    '',
    '',
    '',
    '',
    'yBtY7BaUiGIHMEXzs1UUdr',
    true
  );

-- Tabela de serviços
CREATE TABLE IF NOT EXISTS fiscalidade_services (
  -- Identificador único
  id BIGSERIAL PRIMARY KEY,
  -- Descrição (NF-e, NFC-e etc.)
  description CHARACTER VARYING(50) NOT NULL UNIQUE,
  -- Serviço (nfe, nfce etc.)
  slug CHARACTER VARYING(50) NOT NULL UNIQUE,
  -- Ativo
  active BOOLEAN NOT NULL DEFAULT TRUE,
  -- Data de cadastro
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- Tabela para relacionar serviço a contribuinte
CREATE TABLE IF NOT EXISTS fiscalidade_taxpayers_services (
  id BIGSERIAL PRIMARY KEY,
  -- ID do contribuinte
  taxpayer_id BIGINT NOT NULL REFERENCES fiscalidade_taxpayers (id) ON UPDATE CASCADE ON DELETE CASCADE,
  -- ID do serviço
  service_id BIGINT NOT NULL REFERENCES fiscalidade_services (id) ON UPDATE CASCADE ON DELETE CASCADE,
  -- Data de permissão
  allowed_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
  -- Data de cadastro
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
  UNIQUE (taxpayer_id, service_id)
);

-- Insere serviços disponíveis.
INSERT INTO fiscalidade_services (description, slug)
VALUES
  ('NF-e', 'nfe');

Partially related/fixable by: #507

@mtxr
Copy link
Owner

mtxr commented May 12, 2020

Fixed by #507

@mtxr mtxr closed this as completed May 12, 2020
@mtxr mtxr added this to the v0.22 milestone May 12, 2020
@mtxr mtxr self-assigned this May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants