Dedicated database sharing between two apps on Heroku - ruby-on-rails-3

I have two apps on Heroku and I would like them to use the same dedicated database. The problem is that this new app has the same models/tables than the other one.
My questions are:
Should I change the name for the tables on the new app?
If yes, what about the name of my models? Is it possible to map a model with a table with a different name? (Like User model with new_user table instead of user).
Any good advices on how to do this will be appreciated.
Thanks!

In general this is probably not as good an idea as it may seem. Rails is designed to assume it has 100% control over the database.
Even if you are able to get your tables separated and not colliding, you will still have challenges with the schema_migrations table. That table holds all the migrations for rails and would contain a mix of all migration records for both applications. This would confuse the apps whenever, for example, you tried to run rake db:rollback or other rake commands.
There could also be issues with having your schema.rb file potentially get out of synch between the two applications.
I'd recommend looking hard at the reasons you want to share the database and see if there are other ways to accomplish what you are trying to do. For example, you might consider using Active Resources to connect the applications restfully.

Related

SQL database management question for Webscraper project

I have very little Database management experience, I took a single class when I was in Undergrad. I wanted to see other's inputs on the best way to setup the database.
I have developed a docker application(Webscraping, PostGIS database). The webscraper scrapes from multiple websites everyday. Then uploads to the database, it also checks for duplicates before uploading to the database.
However, I don't want the Reasearch Assistants to be able to change things on the original tables, since lot of the webscraper depends on the structure of the original tables. I gave them SELECT access, but I want them to be able to share their data on the Database as this is a collaborative project.
My original thoughts was to create a new and empty database with full permission. And only SELECT access to the webscraper database. I don't know if this is the best way to do this.
What are your thoughts?
Also to note, this is a contract job for a university project under a grant so I won't be maintaining the database after the contract. Also the project isn't big enough to hire a person with Docker & Database experience just to maintain the database. So I am trying to bulletproof this as much as possible.

Should I make a separate database for each application?

I’m building two applications that need to share some similar data but each will also have unique data. Should I build a separate database for each app or let each app access the same database.
I need the shared data to update automatically on one app if it is changed in another. I’m also using postgresql with react and express with the intent of having both apps be progressive web apps and eventually react native apps.
In general, I would think of this as:
Databases are the unit of backup and recovery.
Databases can contain multiple schemas ("schemata" ?) which are the unit for managing users and objects.
Based on your question:
I need the shared data to update automatically on one app if it is changed in another.
It sounds like you want one database and separate schemas for each application.
It sounds as if you will need to join the database from both applications in a single SQL query. In that case, use one database and multiple schemas to separate the data.
You could have one schema common that contains the data which is shared between all applications and then one schema per application.
Both has pros and cons. But i think keeping them separate will be better. Pro for one can be con for other.
Pros -
separate DB makes maintenance better,faster and easy.
performance wise separate DB is better.
Migrations of code will be easy.
Cons -
Auto synchup can be tricky if tables etc. are different.
If one process need to use tables from both DB, it will be an issue.

How to prevent errors when removing tables in the database used in Azure Mobile Services?

When I remove tables used in my Azure database (of course after removing the entities), I just use DROP TABLE TABLENAME. This has a bad effect. When I run the mobile service by just starting the browser, I get an Error 500 when I add a new record (of an existing table of course) with my TableControllers. Apparently, I did something wrong. It can be "solved" by creating a completely new database and use this one in my mobile service. The Seed method ensures that the right tables exist (and only the right tables) and everything works fine.
What is the best way (to prevent errors) when removing tables in a database used in Azure Mobile Services. Creating a completely new database seems to be a bit overdone and unneeded.
My first instinct is that it's an issue with Entity Framework. It doesn't generally play nicely with people touching the database. If you looked through your log, you'd probably see Entity Framework issues.
Take a look at this Azure Doc: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-use-code-first-migrations/
It discusses how to enable code first migrations - I won't elaborate here because there are a couple of steps.
Essentially, the problem is that Entity Framework takes a number of dependencies and when those dependencies change, it just falls over on itself. Let me know if that doesn't help you.

Creating "Archive" database to unload application "Main" database

I want to create a web application that is supposed to contain a lot of data. I want to ask if anyone of you have ever met a system that contained two databases - main and archive. I want to create a mechanism that will move old data from main database to archive database in order to unload it. For instance, when I have a table of user accounts, I want to move the ones that weren't used for, say, more than three months to an archive database. Having this done, main database may be significantly unloaded so I expect it to work faster. However such mechanism has to work in two directions - not only migrating from main to archive but also from archive to main db in order to allow user's to "refresh" their accounts. Of course in such scenario I will use GUID's instead of BIGINT's as PRIMARY KEY. What do you think about it? Is such concept right or I shouldn't bother about it and assume that there should be only one database? Thanks in advance.
Having archive database never hurts, but usually it's used for restoring or reporting. I think in most cases partitioning will serve your purpose better. Also, many RDMS systems propose different solutions out of the box, like database clustering, mirroring, etc.

Can two different sites running on same host, share same database for storage and retrieval?

I am building a personal site, for a blog I wish to use WordPress and for a wiki i will use
wikia. Is it possible that i use the same database for storing articles from both frontends (WordPress and wiki). If yes can i some how populate articles from my wiki to the blog, under a specific category.
EDIT-- By two different sites I mean two different frontends, hosted at different subdomains.
At installation time, both WordPress and Wikka allow you to prefix their tables with different names to prevent naming collisions. So yes it is possible to allow both applications to share the same database.
We have plenty of customers on our shared hosting environment who do this without any issues.
In answer to your second question, you may be in for a bit of custom code to do that.
Why not, its possible, just take care from any tables names conflict between both tables, you may need to edit some tables names.
And about populating one from another, i think you will need to edit its code some how to let it understand the new tables.
A host will put multiple clients on the same database server, so yes.
If you control the database and the apps, then you could code them to "share info"
They can quite happily use the same database. Depending on the RDBMS you are using, you may want to create an additional Database or user instance for each site.
With SQL Server you can create an additional database, or you can add a schema for each site. for Oracle you can create a user specific to each site.
To return data from one place to another, simply build a view which is accessible to each schema. You will need to set privileges on the source database to do this, but that's pretty straightforward.
The short answer is YES.
However, you will need to watch out for database object naming conflicts.
Also, when you say 'two different sites' do you mean 2 different sites? Or just different 'frontends' within the same site? If it just different front apps running in the same website, then you will also have to make sure you won't have any configuration conflicts.
I'm not really sure what your aim is. Is your intention simply to share data between Wordpress and Wikia?
You should not store two unrelated schemas in one database. It's just asking for collisions. Both Wikia and Wordpress maintain their own schemas: they may name different functional database objects the same.
If you want to share data between the two databases, you can set up triggers and views to move data from one to the other without them being in the same database.