Fix boolean fields represented as integers in database schema#2689
Conversation
Changed the data type of public column in user_list to tinyint.
demiankatz
left a comment
There was a problem hiding this comment.
Thanks, @skellamp -- I think we also need to change int to boolean for the equivalent field in pgsql.sql, and we'll also need to add a migration script for PostgreSQL users. I'll put TODO checkboxes in place about all of this -- we should probably test that the change is safe in MySQL before we spend time working on PostgreSQL as well.
There was a problem hiding this comment.
@skellamp, I tried to do a test of upgrading existing data in PostgreSQL using the migration script, but it doesn't seem to be working. Here's what I did:
1.) I started up VuFind with the -Ddbtype=pgsql switch while on the dev branch
2.) I created an account in the instance, created public and private lists, created some search history, and saved a search. This gave me data where I could check that flags were being properly applied after the migration.
3.) I switched to your branch
4.) I ran the migration with psql -U vufindtest -d vufind_test -a -f module/VuFind/sql/migrations/pgsql/9.0/006-modify-boolean-fields.sql
Here's what I got (after entering the default test environment password of "vufindpass"):
--
-- Modifications to table `search`
--
ALTER TABLE "search"
ALTER COLUMN saved TYPE boolean NOT NULL DEFAULT '0';
psql:module/VuFind/sql/migrations/pgsql/9.0/006-modify-boolean-fields.sql:6: ERROR: syntax error at or near "NOT"
LINE 2: ALTER COLUMN saved TYPE boolean NOT NULL DEFAULT '0';
^
--
-- Modifications to table `user_list`
--
ALTER TABLE "user_list"
ALTER COLUMN public TYPE boolean NOT NULL DEFAULT '0';
psql:module/VuFind/sql/migrations/pgsql/9.0/006-modify-boolean-fields.sql:13: ERROR: syntax error at or near "NOT"
LINE 2: ALTER COLUMN public TYPE boolean NOT NULL DEFAULT '0';
I think PostgreSQL syntax requires you to have a separate clause for each thing you change in a row. See, for example, https://github.com/vufind-org/vufind/blob/dev/module/VuFind/sql/migrations/pgsql/3.0/004-modify-seach-columns.sql for something similar.
However, when I tried to adjust the syntax to this style, I still ran into errors about type-casting of data and defaults, so I think a little more work/research is needed. Can you investigate further? Let me know if you need any more help from my end!
demiankatz
left a comment
There was a problem hiding this comment.
Thanks, @skellamp, this looks good and everything is working as expected for me in MySQL and PostgreSQL now.
Changed the data type of public column in user_list to tinyint.
TODO