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

Fix DB Compatibility & small fixes #33

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

Conversation

domrim
Copy link

@domrim domrim commented Jul 10, 2024

I tried to use Pønskelisten with a postgresql database. It didn't work so i fixed the code so it works now. mysql/mariadb should still work perfectly.

also found some redundant code and small bugs which i fixed :)

@aunefyren
Copy link
Owner

Wow, thank you so much for the contribution. I may take me some time to look through this code before merging, but it looks really good! I have learnt a lot as this project evolved so I appreciate the clean up and hope the code wasn't too hard to decipher.

I know my previous Gorm approach didn't support Postgres, but I learned as I went. Your approach is completely new to me so I will have to learn it for future development. This is preferable though, as I want to support more DB formats. Seems to be this approach: https://gorm.io/docs/advanced_query.html

@aunefyren
Copy link
Owner

Still looking through and debugging on the MariaDB side. Your changes didn't work out of the box. I have fixed some issues while (hopefully) maintaining PostGresSQL support.

Now I am stuck at this issue:

groupRecords := Instance.Distinct().
		Debug().
		Group("groups.id").
		Where(&models.Group{Enabled: true}).
		Joins("JOIN `group_memberships` ON `group_memberships`.`group_id` = `groups`.`id`", Instance.Where(&models.GroupMembership{Enabled: true, MemberID: UserID})).
		Find(&groups)

That code produces this MYSQL statement:

SELECT DISTINCT `groups`.`id`,`groups`.`created_at`,`groups`.`updated_at`,`groups`.`deleted_at`,`groups`.`name`,`groups`.`description`,`groups`.`enabled`,`groups`.`owner_id` FROM `groups` JOIN `group_memberships` ON `group_memberships`.`group_id` = `groups`.`id` WHERE `groups`.`enabled` = true AND `groups`.`deleted_at` IS NULL GROUP BY `groups`.`id``

Which does not include the WHERE restrains on GroupMemberships. Not sure why.

Honestly I am considering scrapping MariaDB support altogether and migrating to PostGresSQL.

@domrim
Copy link
Author

domrim commented Nov 27, 2024

i rebased my branch on yours to include the few fixes of the last month ;)

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