Padrino 0.18.0 release
Padrino 0.18.0 is out. It fixes a long list of bugs in the generators and the database rake tasks, makes generated apps safer by default, and adds rake db:dump. It also removes four generator components (the Ohm, MiniRecord and Dynamoid ORMs and Less) whose projects no longer work with current gems, so read the breaking changes below before you upgrade.
Thanks to @achiurizo for his work on this release, and to @ssut, @mistergibson, @Quintasan, @postmodern and @scockram for the reports behind several of these changes. The full list is in CHANGES.rdoc.
Highlights
rake db:dump(sq:dump,ar:dump) dumps a Postgres, MySQL or SQLite database totmp/<env>_dump.sql, or toFILE=. It runspg_dump,mysqldumporsqlite3, which must be on your PATH.- Database tasks that work:
rake db:createcreates a missing Postgres or MySQL database on Active Record 7.1 and later, instead of reporting it as existing.sq:createandsq:dropno longer need thecreatedbandmysqlcommand-line clients.- The Sequel migrate tasks run in a project with no migrations yet.
- Safer generated apps:
- The session cookie is
Securein production. - The session secret comes from
SESSION_SECRETwhen it is set. - Apps that set Sinatra's
host_authorization(Sinatra 4.1 or later) now get that check.
- The session cookie is
- Generators:
- Re-running
padrino g componentkeeps the files you edited. - Field modifiers work in any order (
email:string:uniq:index). - Sequel
referencesfields become indexed foreign keys. - Mongoid models get valid field types.
- Invalid names and options print a message and exit 1, instead of a backtrace.
- Re-running
- The admin uses Bootstrap 3.4.1 (was 3.1.0), and its erb and slim list pages get the right menu classes.
- Fixes in the running app:
- Editing an
ActiveSupport::Concernno longer breaks reloading until a restart. - Apps mounted under a sub-path serve shared assets.
- A malformed URL gets a 404 instead of a 500.
- Sending an email no longer changes how erb templates escape elsewhere in the process.
- WEBrick shuts down cleanly on
TERM.
- Editing an
Breaking changes
- Removed generator components: the Ohm, MiniRecord and Dynamoid ORMs and the Less stylesheet engine. Projects generated with them no longer work with current gems. 0.18 doesn't change how existing apps run, but
padrino g model,g migration,g adminandg admin_pageexit with an error in projects that use one of these ORMs. rake ar:createandar:dropexit non-zero when a database can't be created or dropped, as Rails does. Scripts that ignored those errors now stop there.SqlHelpers.create_dbanddrop_dbtake the app's Sequel connection options (create_db(Sequel::Model.db.opts, charset, collation)), if your Rakefile calls them directly.- Apps mounted under a sub-path serve files from the shared
public/under their prefix when their ownpublic/<app>doesn't have them. Such a file answers before the app's routes: withpublic/robots.txt, an app mounted at/blogserves that file for/blog/robots.txtinstead of its ownget '/robots.txt'. host_authorization: an app that setsset :host_authorization, permitted_hosts: [...]now answers 403 for other hosts. Apps that don't set it are unchanged.- Inflections without ActiveSupport:
singularizekeeps words like status, address and analysis intact. Nested routes withparent: :statususeparams[:status_id](was:statu_id).
Upgrading from 0.17
In your Gemfile, set
gem 'padrino', '~> 0.18.0', then runbundle update padrino. If your Gemfile lists thepadrino-*gems instead ofpadrino, set each one's version and name them:bundle update padrino-core padrino-helpers ....If your project uses Ohm, MiniRecord, Dynamoid or Less, switch it first, and answer yes when asked:
- The ORM:
padrino g component --orm=activerecord(MiniRecord models are Active Record models),--orm=sequelor--orm=mongoid. - Less:
padrino g component --stylesheet=sass(orscss,tailwind).
- The ORM:
After switching, remove what the old component left behind:
- Gemfile: the old gems (
mini_record;rack-less,lessandtherubyracer; Ohm's or Dynamoid's gems). Then runbundle install. - Rakefile:
PadrinoTasks.use(:minirecord). The switch already added the new ORM's line. - MiniRecord:
ActiveRecord::Base.auto_upgrade!inconfig/boot.rb. - Leaving Active Record:
use ConnectionPoolManagementin each app, andlib/connection_pool_management_middleware.rb. - Less:
register LessInitializerinapp/app.rb, andconfig/initializers/less.rb.
Then port your models to the new ORM.
- Gemfile: the old gems (
If a script runs
rake ar:createorar:dropand expects it to carry on after an error, handle the non-zero exit.If an app is mounted under a sub-path, check that no file in the shared
public/has the same path as one of its routes. If no other app needs the file, rename or remove it. Otherwise, give the app a public folder of its own that isn'tpublic/<app>:- for example, create
blog/publicwith a.keepfile, so git keeps it; - move the app's files from
public/bloginto it; - add
set :public_folder, File.join(__dir__, 'public')to the app.
The folder must exist.
- for example, create
If an app sets
host_authorization, make surepermitted_hostslists every host it is served on.- The port doesn't matter.
- Behind a proxy that sends
X-Forwarded-Host(orForwarded: host=), both that host and theHostthe proxy sends must be listed, or have the proxy pass the originalHost. - Rack::Test requests use
example.org, so add it in the test environment, or the app's tests get 403.
In projects without ActiveSupport, check nested routes whose parent ends in -s, -ss or -sis, and the
url(...)calls that pass its id. Projects that load ActiveSupport, including every project with a generated admin, are unaffected.Generated files are yours, so existing projects keep their old defaults. To adopt the new ones:
- Session cookie: change
set :sessions, same_site: :laxtoset :sessions, same_site: :lax, secure: Padrino.env == :productionin every app, includingadmin/app.rb. The apps share one cookie, and an app without it rewrites the cookie withoutSecure. Production then sends the cookie only over HTTPS: served over plain HTTP, logins and form posts fail. Behind a proxy that terminates TLS, have it sendX-Forwarded-Proto: https. - Session secret: in
config/apps.rb, useset :session_secret, ENV.fetch('SESSION_SECRET') { '<your current secret>' }.SESSION_SECRETmust be 64 characters or more (padrino rake secretprints one). An empty or shorter value makes every request fail with a 500. - Admin: to move to Bootstrap 3.4.1, generate an admin in a scratch project and copy
public/admin/stylesheets/bootstrap.css,application.cssandpublic/admin/javascripts/bootstrap/*together. Carry over any changes you made toapplication.css; Font Awesome moved into it. Bootstrap 3.4.1 sanitizes HTML in tooltips and popovers. - Smaller fixes in generated files, if they apply to your project:
- cucumber.yml: use
--tags 'not @wip', and drop--stricton cucumber 12. - Bacon: add
Bacon.summary_on_exitafter the boot line intest/test_config.rb, so a failing suite exits non-zero. - Sequel on Postgres or MySQL: add
test: falseto theSequel.connectcalls inconfig/database.rb, sorake sq:createcan create a missing database. - Mongoid 9: add
Time.zone_default ||= Time.find_zone!('UTC')toconfig/database.rb.
- cucumber.yml: use
- Session cookie: change
Run your test suite and boot the app.
Ruby 2.7.8 or later, Sinatra 4 and Rack 3 are still required, as in 0.17.