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

refactor: Change text fields in CREATED_AT and UPDATED_AT to TIMESTAMPZ type. #60

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

updev-sistemas
Copy link

@updev-sistemas updev-sistemas commented May 11, 2024

🤔 O que foi feito?
Alterado os tipos de dados nas colunas CREATED_AT e UPDATED_AT em todas as tabelas e corrigido mapeamento nos modelos.

📗 Checklist do desenvolvedor

  • Foi testado localmente? Sim
  • Foi adicionado documentação necessária (swagger, testes e etc)? Não,

👀 Checklist do revisor

Revisor 1️⃣

  • Você entendeu o propósito desse PR?
  • Você entendeu o fluxo de negócio?
  • Você entendeu o que e como foi desenvolvido tecnicamente a solução?
  • Você analisou se os testes estão cobrindo a maioria dos casos?

🔗 Referência
Issue #53

@updev-sistemas updev-sistemas changed the title Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. WIP! Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. May 11, 2024
@updev-sistemas updev-sistemas force-pushed the change-timestamp-data branch 2 times, most recently from 699b4e1 to 43f83ab Compare May 11, 2024 14:34
@updev-sistemas updev-sistemas changed the title WIP! Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. May 11, 2024
@updev-sistemas updev-sistemas changed the title Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. WIP!Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. May 11, 2024
@updev-sistemas updev-sistemas force-pushed the change-timestamp-data branch from 43f83ab to 3602e0c Compare May 11, 2024 14:49
@updev-sistemas updev-sistemas changed the title WIP!Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. May 11, 2024
@updev-sistemas
Copy link
Author

updev-sistemas commented May 11, 2024

Esse MR, altera o tipo de dado em CREATED_AT e UPDATED_AT, em cada tabela, de varchar para TIMESTAMP WITH TIME ZONE.
Alterados mapeamento dos modelos, fazendo remoção de ".toISOString()" na camada de serviço.

Issue #53

@updev-sistemas updev-sistemas force-pushed the change-timestamp-data branch 2 times, most recently from 0941d8b to ae8a806 Compare May 11, 2024 16:14
@rafaelvargas
Copy link

Oi, @updev-sistemas. Uma sugestão: ao invés de usar colunas temporárias, a migração poderia usar uma abordagem como:

ALTER TABLE  
    "category_supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING 
    TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP AT TIME ZONE 'UTC';

Me parece também que as expressões regulares, sendo usadas nos testes nas cláusulas CASE , não seguem o formato dos valores que estão sendo salvos atualmente no banco, que seguem o formato especificado na ISO 8601. Considerando o teste a seguir, como exemplo, obtemos um valor falso:

SELECT 
	'2024-05-07T07:32:25.144Z' ~* '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$';

Desta forma, todos os testes iriam "cair" no ELSE.

Além disso, vale notar que a função TO_TIMESTAMP gera valores com o fuso horário padrão definido no banco, portanto, deve-se garantir que apenas o valor do timestamp (sem o time zone) seja obtido (::TIMESTAMP) e, posteriormente, se defina o fuso de maneira explícita (AT TIME ZONE '+00:00') (no caso em questão, +00:00, dado que os valores atualmente salvos possuem "Z" ao final):

TO_TIMESTAMP(created_at, 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP AT TIME ZONE '+00:00';

@updev-sistemas updev-sistemas force-pushed the change-timestamp-data branch from ae8a806 to 6a4f4b9 Compare May 11, 2024 17:14
@updev-sistemas
Copy link
Author

updev-sistemas commented May 11, 2024

ALTER TABLE  
    "category_supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING 
    TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP AT TIME ZONE 'UTC';

Migration executada com branch DEVELOP e aplicado restore do arquivo "dev_dump.sql", em seguida, aplicada migration com a minha branch, que atualiza os campos nas tabelas.

Resultados obtidos.
image

Scripts ajustados.

@updev-sistemas updev-sistemas force-pushed the change-timestamp-data branch from 6a4f4b9 to e0f9c28 Compare May 11, 2024 17:17
@updev-sistemas updev-sistemas changed the title Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. refactor: Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. May 11, 2024
@updev-sistemas updev-sistemas changed the title refactor: Change create_at and updated_at to TIMESTAMP WITH TIME ZONE. refactor: Change created_at and updated_at to TIMESTAMP WITH TIME ZONE. May 11, 2024
@updev-sistemas updev-sistemas changed the title refactor: Change created_at and updated_at to TIMESTAMP WITH TIME ZONE. refactor: Change created_at and updated_at to TIMESTAMPZ. May 11, 2024
@updev-sistemas updev-sistemas changed the title refactor: Change created_at and updated_at to TIMESTAMPZ. refactor: Change text fields in CREATED_AT and UPDATED_AT to TIMESTAMPZ type. May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants