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

Fixes #24838 - Use integer representation for boolean on sqlite #7171

Merged
merged 1 commit into from
Nov 19, 2019

Conversation

tbrisker
Copy link
Member

We don't really need to migrate boolean fields as sqlite isn't supported
production database and is only used for running build tasks.

@theforeman-bot
Copy link
Member

Issues: #24838

@tbrisker
Copy link
Member Author

tbrisker commented Nov 11, 2019

Migration is not trivial, most fields can be converted using the following task but there are many that aren't covered in it (either in core or in plugins):

      if ActiveRecord::Base.connection.adapter_name.downcase.starts_with?('sqlite')
        ActiveRecord::Base.connection.tables.map do |t|
          t.classify.constantize rescue nil
        end.compact.each do |t|
          next unless t.respond_to? :columns
          t.columns.each do |col|
            next unless col.type == :boolean
            next if col.name == 'default'
            t.where("#{col.name} = 't'").update_all(col.name.to_sym => 1)
            t.where("#{col.name} = 'f'").update_all(col.name.to_sym => 0)
          end
        end
      end

@mmoll
Copy link
Contributor

mmoll commented Nov 11, 2019

We might also declare SQLite as dev only and unsafe for upgrades or similar ;)

adamruzicka
adamruzicka previously approved these changes Nov 11, 2019
Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

Haven't tested the migration, but the actual patch makes sense and works nicely for me.

@mmoll
Copy link
Contributor

mmoll commented Nov 11, 2019

upgrade test fails 💔

@tbrisker
Copy link
Member Author

that's wierd, it failed to create an admin user on 1.14... [test upgrade]

@mmoll
Copy link
Contributor

mmoll commented Nov 12, 2019

@tbrisker Perhaps it's saved in the "old" format on the old Rails version and with that setting the new Rails isn't detecting it correctly?

@tbrisker
Copy link
Member Author

@mmoll it is, the seed is failing to find it due to the way it checks for existing admin user. I'll work around that in a second.

We don't really need to migrate boolean fields as sqlite isn't supported
production database and is only used for running build tasks.
@@ -42,11 +42,13 @@
end

# First real admin user account
unless User.unscoped.only_admin.except_hidden.present?
Copy link
Member Author

Choose a reason for hiding this comment

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

only_admin doesn't find the exising admin user when upgrading due to the changed format. I've made this seed more sensitive so it first checks if a user with the admin login exists, which will also be good so it doesn't fail when trying to seed an existing user name.

Copy link
Contributor

@mmoll mmoll left a comment

Choose a reason for hiding this comment

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

Fine for me 👍. @tbrisker Could you add an 1.24 upgrade warning with the migration script? I hope, not many people are using sqlite, especially in production...

@tbrisker
Copy link
Member Author

Opened theforeman/theforeman.org#1501 but looks like we actually default to SQLite on non-installer installations, I wonder how many users we have that use sqlite in production due to this.

@tbrisker
Copy link
Member Author

opened an RFC on discourse to make sure we can really drop sqlite in production: https://community.theforeman.org/t/dropping-support-for-sqlite-as-production-database/16158

@mmoll mmoll merged commit f335055 into theforeman:develop Nov 19, 2019
@mmoll
Copy link
Contributor

mmoll commented Nov 19, 2019

merged, thanks @tbrisker!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants