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

Allows publishing on systems with table prefixes #80

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bombozama
Copy link

@bombozama bombozama commented Jan 10, 2022

Found a bug. I'm using typeorm in multiple systems sharing the same database, so I need my burdy install to have it's tables prefixed (i.e. blog_posts). Turns out that typeorm doesn't support table aliases when updating (and won't support them in the future): typeorm/typeorm#1798. This PR fixes it.

I'm getting a Unknown column 'post.id' in 'where clause error when attempting to publish/unpublish items.

Generated query:

UPDATE `blog_post` SET `publishedAt` = '2022-01-10 03:03:15.945', `status` = 'published', `publishedFrom` = '2022-01-10 03:03:15.945', `publishedUntil` = NULL, `updatedAt` = '2022-01-10 03:03:15.945' WHERE post.id IN (1, 2, 3)

Steps to reproduce:

  • Set up a table prefix with the TYPEORM_ENTITY_PREFIX .env var
  • Attempt to publish a post.

Found a bug. I'm using typeorm in multiple systems sharing the same database, so I need my burdy install to have it's tables prefixed (i.e. `blog_posts`). Turns out that typeorm doesn't support table aliases when updating (and won't support them in the future): typeorm/typeorm#1798. This PR fixes it.

I'm getting a "Unknown column 'post.id' in 'where clause" error when attempting to publish/unpublish items.

Generated query:
UPDATE `blog_post` SET `publishedAt` = '2022-01-10 03:03:15.945', `status` = 'published', `publishedFrom` = '2022-01-10 03:03:15.945', `publishedUntil` = NULL, `updatedAt` = '2022-01-10 03:03:15.945' WHERE post.id IN (1, 2, 3)

Steps to reproduce:
- Set up a table prefix with the `TYPEORM_ENTITY_PREFIX`
- Attempt to publish a post.
@stefan-burdy
Copy link
Contributor

Hi @bombozama,

Nice find! Is this the only API that's being affected? There are more places where this is being used. Are they affected as well?

In that case, it might make sense to abstract the TypeORM query or patch the relevant query builder functions.

@bombozama
Copy link
Author

bombozama commented Jan 10, 2022

I've been looking (not too hard) for other aliased updates within burdy but haven't been able to find any others. Let me take a deeper look and I'll let you know.

@bombozama
Copy link
Author

bombozama commented Jan 11, 2022

So I found the problem in just three places:

  • Post controller
  • Asset controller
  • Tag controller

Asides from the fix in the first commit, the only other places I could find the same problem were when getReplaceChildrenQuery helper was invoked.

In my opinion, no additional abstraction is needed, just considering the case in the future should suffice. Please note that the problem is only on aliased update statements. Selects work like a charm no need to reconfigure anything else.

Hope it helps.

@sandra-burdy
Copy link
Contributor

Hi @bombozama thank you very much! Ill take a look at it tomorrow

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.

3 participants