5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 04:56:21 +00:00

serializar booleanos en sqlite3

This commit is contained in:
f 2019-07-12 14:11:24 -03:00
parent 237cfb4a5e
commit 3171ca7177
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
4 changed files with 46 additions and 8 deletions

View file

@ -19,13 +19,18 @@ require 'rails/test_unit/railtie'
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
module Sutty module Sutty
# Sutty!
class Application < Rails::Application 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 config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those
# Application configuration should go into files in config/initializers # specified here. Application configuration should go into files in
# -- all .rb files in that directory are automatically loaded. # config/initializers -- all .rb files in that directory are
config.action_dispatch.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden # automatically loaded.
config.action_dispatch
.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden
config.active_record.sqlite3.represent_boolean_as_integer = true
end end
end end

View file

@ -44,7 +44,10 @@ class CreateSitios < ActiveRecord::Migration[5.2]
usuarie ||= Usuarie.create(email: email, usuarie ||= Usuarie.create(email: email,
password: SecureRandom.hex, password: SecureRandom.hex,
confirmed_at: Date.today) 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 end
invitadxs.each do |email| invitadxs.each do |email|
@ -52,7 +55,9 @@ class CreateSitios < ActiveRecord::Migration[5.2]
usuarie ||= Usuarie.create(email: email, usuarie ||= Usuarie.create(email: email,
password: SecureRandom.hex, password: SecureRandom.hex,
confirmed_at: Date.today) 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 end
end end

View 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

View file

@ -12,7 +12,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table 'roles', force: :cascade do |t|
t.datetime 'created_at', null: false t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false t.datetime 'updated_at', null: false