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

Add support for more locales #42

Open
samuel02 opened this issue Jan 15, 2021 · 3 comments
Open

Add support for more locales #42

samuel02 opened this issue Jan 15, 2021 · 3 comments

Comments

@samuel02
Copy link

I would like to use this but run into problems since I need to support collation sv_SE on some columns. I have added a rake task:

namespace :db do
  task add_collation: [:environment] do
    puts "Adding sv_SE collation..."
    ActiveRecord::Base.connection.execute("SET search_path TO 'public'; CREATE COLLATION sv_SE (locale = 'sv_SE.UTF-8');")
  end
end

Rake::Task['db:structure:load_if_sql'].enhance [:add_collation]

But when using heroku-postgres:in-dyno I'm getting:

ActiveRecord::StatementInvalid: PG::InvalidParameterValue: ERROR:  could not create locale "sv_SE.UTF-8": No such file or directory
       DETAIL:  The operating system could not find any locale data for the locale name "sv_SE.UTF-8".

Is there an easy way to add more locales in the buildpack?

@edmorley
Copy link
Member

@samuel02 Hi! I would try running the locale buildpack prior to the existing buildpacks:
https://github.com/heroku/heroku-buildpack-locale

@samuel02
Copy link
Author

@edmorley thanks for the suggestion! I tried updating my app.json to:

{
  "environments": {
    "test": {
      "addons": [
         "heroku-redis:in-dyno",
         "heroku-postgresql:in-dyno"
      ],
      "buildpacks": [
        {"url":  "https://github.com/heroku/heroku-buildpack-locale"},
        {"url":  "https://github.com/heroku/heroku-buildpack-ruby"}
      ],
      "env": {
        "LANG": "sv_SE.utf8"
      }
    }
  }
}

But still getting the same error. I see that it is installing language packs but for some reason Postgres doesn't seem to pick it up? Any ideas?

@edmorley
Copy link
Member

I'm not very familiar with Postgres locales, so not sure.

I would say the issue is one of:

  1. The locales need to be in place before the postgres server is started
  2. The locales need to be in place before the postgres DB is initialised
  3. One of the settings here needs changing/overriding:
    export PGDATA=$BUILD_DIR/.indyno/vendor/postgresql/data
    LC_COLLATE=en_US.UTF-8 \
    LC_CTYPE=en_US.UTF-8 \
    LC_MESSAGES=en_US.UTF-8 \
    LC_MONETARY=en_US.UTF-8 \
    LC_NUMERIC=en_US.UTF-8 \
    LC_TIME=en_US.UTF-8 \
    initdb -E UTF8 | indent

Re (1)/(2): If the in-dyno PG buildpack is automatically added by Heroku CI (due to having heroku-postgresql:in-dyno under the test.addons key in app.json), then it's added before all other buildpacks. If you wanted to try having it run after the locale buildpack, you could remove heroku-postgresql:in-dyno from addons and explicitly add this buildpack to buildpacks (either via the heroku/ci-postgresql buildpack registry alias, or the GitHub URL https://github.com/heroku/heroku-buildpack-ci-postgresql -- in general the buildpack registry aliases are preferred).

To try with (3), I'd first try forking this buildpack, adding it directly to buildpacks and removing heroku-postgresql:in-dyno from addons (as above) and adjusting the settings. If that works you could then try switching back to the non-forked buildpack and seeing if the settings can be updated retrospectively when your CI run starts, to save having to maintain a forked buildpack.

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

No branches or pull requests

2 participants