Last active
August 28, 2023 18:03
-
-
Save beneggett/f1d28a6e2cc05fd48bfa to your computer and use it in GitHub Desktop.
Postgresql multiple schemas in rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DbSetup < ActiveRecord::Migration | |
def up | |
create_schema :oauth | |
create_table "oauth.oauth_applications" do |t| | |
t.string :name, null: false | |
t.string :uid, null: false | |
t.string :secret, null: false | |
t.text :redirect_uri, null: false | |
t.integer :owner_id, null: false | |
t.string :owner_type, null: false | |
t.timestamps | |
end | |
create_table "oauth.oauth_access_grants" do |t| | |
t.integer :resource_owner_id, null: false | |
t.integer :application_id, null: false | |
t.string :token, null: false | |
t.integer :expires_in, null: false | |
t.text :redirect_uri, null: false | |
t.datetime :created_at, null: false | |
t.datetime :revoked_at | |
t.string :scopes | |
end | |
create_table "oauth.oauth_access_tokens" do |t| | |
t.integer :resource_owner_id | |
t.integer :application_id | |
t.string :token, null: false | |
t.string :refresh_token | |
t.integer :expires_in | |
t.datetime :revoked_at | |
t.datetime :created_at, null: false | |
t.string :scopes | |
end | |
create_table("oauth.oauth_users") do |t| | |
t.string :email, null: false, default: "" | |
t.string :encrypted_password, null: true, default: "" | |
t.string :reset_password_token | |
t.datetime :reset_password_sent_at | |
t.datetime :remember_created_at | |
t.integer :sign_in_count, default: 0, null: false | |
t.datetime :current_sign_in_at | |
t.datetime :last_sign_in_at | |
t.inet :current_sign_in_ip | |
t.inet :last_sign_in_ip | |
t.string :invitation_token | |
t.datetime :invitation_created_at | |
t.datetime :invitation_sent_at | |
t.datetime :invitation_accepted_at | |
t.integer :invitation_limit | |
t.references :invited_by, :polymorphic => true | |
t.integer :invitations_count, default: 0 | |
t.index :invitations_count | |
t.index :invitation_token, :unique => true | |
t.index :invited_by_id | |
t.integer :oauth_application_id | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Declare schema search path in your database.yml file (in this example i'm using oauth as a schema name) | |
development: | |
username: myuser | |
password: mypass | |
adapter: postgresql | |
encoding: unicode | |
database: my_app_development | |
pool: 75 | |
schema_search_path: "oauth,public" | |
## Now your schema.rb file will look at both the oauth, and public schemas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OauthAccessToken < ActiveRecord::Base | |
self.table_name = 'oauth.oauth_access_tokens' | |
# .... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You may need to declare the table explicitly in your models (may == will) | |
class User < ActiveRecord::Base | |
self.table_name = 'oauth.users' | |
# .... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment