Coder Social home page Coder Social logo

roomer's People

Contributors

boz avatar dceballos avatar dcleven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

roomer's Issues

breaks when models use `set_table_name`.

The table_name_prefix configured by roomer isn't used by AR's reset_table_name when set_table_name has been called. Models that use set_table_name end up not having a schema.

This breaks doorkeeper, at least. I haven't tested a non-engine model to see if it would suffer from the same problem.

inconsistent index name generated between tenanted schema create via migrate and Tenant.create

I added a new table (and model) along with a unique index to the tenanted schema via rake roomer:tenanted:migrate and all went well. However, if after the migration, when I issue Tenant.create it fails with the following error:

-- add_index("corporate_advertisers", ["company_id"], {:name=>"company_id", :unique=>true})
ActiveRecord::StatementInvalid: PGError: ERROR: relation "company_id" already exists
: CREATE UNIQUE INDEX "company_id" ON "poindexter"."corporate_advertisers" ("company_id")

The problem appears to be due to inconsistencies in the output of the schema creation when done via tenant record creation, specifically the generated name of the index.

via migrate:

CREATE UNIQUE INDEX "index_wendy.corporate_advertisers_on_company_id" ON "wendy"."corporate_advertisers" ("company_id")

via Tenant.create!:

CREATE UNIQUE INDEX "company_id" ON "poindexter"."corporate_advertisers" ("company_id")

In a given postgres namespace (schema) you can not have two indexes with the same name, and as it happens when the schema is created via the Tenant.create two of different add_index statements are resolving to the same name, they are:

add_index "addresses", ["company_id", "name"], :name => "company_id", :unique => true

add_index :corporate_advertisers, :company_id, :unique => true

For whatever reason the index name generated by Tenant.create is way different from the one generated via migrate. I also noticed that if I rollback the migration, then change the add_index statement in the migration file to:

add_index :corporate_advertisers, :company_id, :unique => true, :name => 'corporate_advertisers_company_id'

Then run the migration, the index name is created as specified above. However, Tenant.create will still try and create the index with the name 'company_id' and ignores the :name option.

After doing a bit of digging, I noticed that in the /schemas/tenanted_schema.rb file the add_index statement listed as:

add_index "corporate_advertisers", ["company_id"], :name => "company_id", :unique => true

event though I explicitly specified the :name option in the migration file. I did find that I can manually change the :name option in tenanted_schema.rb to match what was in the migration rb and that temporarily fixes the problem, but that change gets overwritten whenever I run a migration.

rake db:seed error

PGError: ERROR: relation "schema_migrations" does not exist
LINE 4: WHERE a.attrelid = '"schema_migrations"'::regcl...
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"schema_migrations"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Tasks: TOP => db:seed => db:abort_if_pending_migrations

case sensitive comparison in lookup based on Tenant.url_identifier

if I create a tenant.. Tenant.create(:url_identifier => "SomePlace.lvh.me", :schema_name = "SomePlace")

Then attempt to navigate via a browser to the app using http://SomePlace.lvh.me:3000/

An error is returned via Roomer...

No tenant found for 'someplace.lvh.me' url identifier

This is due to the method current_tenant defined in lib/roomer/extensions/controller.rb and case-sensitive comparisons in the postgresSQL database

def current_tenant
@current_tenant ||= Roomer.tenant_model.find_by_url_identifier(url_identifier)
end

Because postgres uses case sensitive string comparision and the url is stored in the database with mixed case while the url returned by request.host is lowercase the tenant record is not found.

Add migration generators

Migration Generator methods

  • rails generate roomer:global:migration [migration_name] [attribute:type]
  • rails generate roomer:global:migration [migration_name] [attribute:type]

index migration helpers with shared schema broken.

Given shared table foo,

  • add_index(:foo,:bar) creates an index called global."index_global.foo_on_bar" (with the quotes).
  • remove_index(:foo,:bar) tries to remove an index called index_global.global.foo_on_bar.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.