Skip to content

feat: alter create user to also create an account with 1000 as amount#7

Draft
danielkv7 wants to merge 3 commits intomainfrom
feat/add_account_domain
Draft

feat: alter create user to also create an account with 1000 as amount#7
danielkv7 wants to merge 3 commits intomainfrom
feat/add_account_domain

Conversation

@danielkv7
Copy link
Owner

Create following files:

  • account migration
  • account schema

@danielkv7 danielkv7 self-assigned this May 5, 2021
@danielkv7 danielkv7 requested a review from renanlage May 5, 2021 16:38
@danielkv7 danielkv7 changed the title feat: add account migration and schema files feat: alter create user to also create an account with 1000 as amount May 10, 2021
Logger.info("User successfully inserted", email: inspect(user.email))
{:ok, user}

{:error, %{errors: [email: {"has already been taken", _}]}} ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Osh, esse caso de erro ainda pode acontecer, não?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provavelmente o erro vai estourar no controller qnd acontecer

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siimm, vou refazer o controller namoral agora


create(unique_index(:accounts, [:account_number]))

execute "ALTER SEQUENCE accounts_account_number_seq START with 10000 RESTART"
Copy link
Collaborator

@renanlage renanlage May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tem um problema em expor numeros sequenciais publicamente q eh revelar coisas como: quantidade de contas no banco e velocidade em que elas são abertas. No geral, é preferível usar números aleatórios mas não precisa mudar

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eu pensei nisso, mas fiquei com duvida de como faria isso na aplicação. Pois se gerar um número randomico que já exista no banco, ele iria ficar tentando várias vezes até conseguir um número vago (isso quando tiver muitos registros de account number). Tem alguma sugestão para isso?

Copy link
Collaborator

@renanlage renanlage May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoje acontece conflito e a gente retenta e tem resolvido so far. Com 6 digitos são 1 milhão de contas, demora atéo conflito virar um problema.

Mas temos uma todo pra resolver isso inclusive. O jeito que pensei é gerar tds os numeros possiveis (até x digitos) e subtrair os existentes numa query (da pra fzr no postgres essa geracao e subtracao), cachear esses numeros e ir tirando aleatoriamente da lista. O cache pode durar alguns minutos pra nao precisar ir no banco toda vez gerar essa lista. Se o cache for numa storage externa tipo redis nem precisa ir no banco de novo, só usar ele pra armazenar essa pool de contas disponiveis

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É nois, Vou tentar gerar um novo concorrente de peso aqui então.

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.

2 participants