mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 22:51:41 +00:00
serializar booleanos en sqlite3
This commit is contained in:
parent
237cfb4a5e
commit
3171ca7177
4 changed files with 46 additions and 8 deletions
|
@ -19,13 +19,18 @@ require 'rails/test_unit/railtie'
|
|||
Bundler.require(*Rails.groups)
|
||||
|
||||
module Sutty
|
||||
# Sutty!
|
||||
class Application < Rails::Application
|
||||
# Initialize configuration defaults for originally generated Rails version.
|
||||
# Initialize configuration defaults for originally generated Rails
|
||||
# version.
|
||||
config.load_defaults 5.1
|
||||
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
# Application configuration should go into files in config/initializers
|
||||
# -- all .rb files in that directory are automatically loaded.
|
||||
config.action_dispatch.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden
|
||||
# Settings in config/environments/* take precedence over those
|
||||
# specified here. Application configuration should go into files in
|
||||
# config/initializers -- all .rb files in that directory are
|
||||
# automatically loaded.
|
||||
config.action_dispatch
|
||||
.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden
|
||||
config.active_record.sqlite3.represent_boolean_as_integer = true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,7 +44,10 @@ class CreateSitios < ActiveRecord::Migration[5.2]
|
|||
usuarie ||= Usuarie.create(email: email,
|
||||
password: SecureRandom.hex,
|
||||
confirmed_at: Date.today)
|
||||
site.usuaries << usuarie
|
||||
|
||||
sql = "insert into sites_usuaries (site_id, usuarie_id)
|
||||
values (#{site.id}, #{usuarie.id});"
|
||||
ActiveRecord::Base.connection.execute(sql)
|
||||
end
|
||||
|
||||
invitadxs.each do |email|
|
||||
|
@ -52,7 +55,9 @@ class CreateSitios < ActiveRecord::Migration[5.2]
|
|||
usuarie ||= Usuarie.create(email: email,
|
||||
password: SecureRandom.hex,
|
||||
confirmed_at: Date.today)
|
||||
site.invitades << usuarie
|
||||
sql = "insert into invitades_sites (site_id, usuarie_id)
|
||||
values (#{site.id}, #{usuarie.id});"
|
||||
ActiveRecord::Base.connection.execute(sql)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
28
db/migrate/20190712165059_sqlite_boolean.rb
Normal file
28
db/migrate/20190712165059_sqlite_boolean.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Convertir los valores binarios de sqlite
|
||||
class SqliteBoolean < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
return unless adapter_name == 'SQLite'
|
||||
|
||||
Usuarie.where("acepta_politicas_de_privacidad = 't'")
|
||||
.update_all(acepta_politicas_de_privacidad: 1)
|
||||
Usuarie.where("acepta_politicas_de_privacidad = 'f'")
|
||||
.update_all(acepta_politicas_de_privacidad: 0)
|
||||
|
||||
change_column :usuaries, :acepta_politicas_de_privacidad, :boolean,
|
||||
default: 0
|
||||
end
|
||||
|
||||
def down
|
||||
return unless adapter_name == 'SQLite'
|
||||
|
||||
Usuarie.where('acepta_politicas_de_privacidad = 1')
|
||||
.update_all(acepta_politicas_de_privacidad: 't')
|
||||
Usuarie.where('acepta_politicas_de_privacidad = 0')
|
||||
.update_all(acepta_politicas_de_privacidad: 'f')
|
||||
|
||||
change_column :usuaries, :acepta_politicas_de_privacidad, :boolean,
|
||||
default: 'f'
|
||||
end
|
||||
end
|
|
@ -12,7 +12,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20_190_711_183_726) do
|
||||
ActiveRecord::Schema.define(version: 20_190_712_165_059) do
|
||||
create_table 'roles', force: :cascade do |t|
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
|
|
Loading…
Reference in a new issue