mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Update migration to use disable_ddl_transaction! and add up/down methods
This commit is contained in:
parent
6dfc0099e1
commit
289a2a5373
4 changed files with 24 additions and 8 deletions
|
|
@ -22,6 +22,7 @@ module Api
|
||||||
|
|
||||||
if @place.save
|
if @place.save
|
||||||
add_tags if tag_ids.present?
|
add_tags if tag_ids.present?
|
||||||
|
@place = current_api_user.places.includes(:tags, :visits).find(@place.id)
|
||||||
|
|
||||||
render json: serialize_place(@place), status: :created
|
render json: serialize_place(@place), status: :created
|
||||||
else
|
else
|
||||||
|
|
@ -32,6 +33,8 @@ module Api
|
||||||
def update
|
def update
|
||||||
if @place.update(place_params)
|
if @place.update(place_params)
|
||||||
set_tags if params[:place][:tag_ids]
|
set_tags if params[:place][:tag_ids]
|
||||||
|
@place = current_api_user.places.includes(:tags, :visits).find(@place.id)
|
||||||
|
|
||||||
render json: serialize_place(@place)
|
render json: serialize_place(@place)
|
||||||
else
|
else
|
||||||
render json: { errors: @place.errors.full_messages }, status: :unprocessable_entity
|
render json: { errors: @place.errors.full_messages }, status: :unprocessable_entity
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ module Omniauthable
|
||||||
|
|
||||||
if user
|
if user
|
||||||
# Update provider and uid for existing user (first-time linking)
|
# Update provider and uid for existing user (first-time linking)
|
||||||
user.update(provider: provider, uid: uid)
|
user.update!(provider: provider, uid: uid)
|
||||||
return user
|
return user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,12 @@ OMNIAUTH_PROVIDERS =
|
||||||
else
|
else
|
||||||
# Cloud: only GitHub and Google
|
# Cloud: only GitHub and Google
|
||||||
providers = []
|
providers = []
|
||||||
providers << :github if ENV['GITHUB_OAUTH_CLIENT_ID'].present?
|
|
||||||
providers << :google_oauth2 if ENV['GOOGLE_OAUTH_CLIENT_ID'].present?
|
if ENV['GITHUB_OAUTH_CLIENT_ID'].present? && ENV['GITHUB_OAUTH_CLIENT_SECRET'].present?
|
||||||
providers
|
providers << :github
|
||||||
|
end
|
||||||
|
|
||||||
|
if ENV['GOOGLE_OAUTH_CLIENT_ID'].present? && ENV['GOOGLE_OAUTH_CLIENT_SECRET'].present?
|
||||||
|
providers << :google_oauth2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
class AddOmniauthToUsers < ActiveRecord::Migration[8.0]
|
class AddOmniauthToUsers < ActiveRecord::Migration[8.0]
|
||||||
def change
|
disable_ddl_transaction!
|
||||||
add_column :users, :provider, :string unless column_exists? :users, :provider
|
|
||||||
add_column :users, :uid, :string unless column_exists? :users, :uid
|
def up
|
||||||
add_index :users, [:provider, :uid], unique: true, algorithm: :concurrently
|
add_column :users, :provider, :string unless column_exists?(:users, :provider)
|
||||||
|
add_column :users, :uid, :string unless column_exists?(:users, :uid)
|
||||||
|
add_index :users, [:provider, :uid], unique: true, algorithm: :concurrently, if_not_exists: true
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_index :users, column: [:provider, :uid], algorithm: :concurrently, if_exists: true
|
||||||
|
remove_column :users, :uid if column_exists?(:users, :uid)
|
||||||
|
remove_column :users, :provider if column_exists?(:users, :provider)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue