I am very new to rails, and from what i have been reading and watching in tutorials only helps me build things from scratch, creating new databases and the models at the same time.
my company has an accounting / construction project management software system that was recently warehoused into ms sql server.
how would i build the models from the existing tables structure . im not needing delete update. im looking to create a remote web based querying tool.
thanks.
Connecting Rails to SQL server is a separate issue which has been covered a bit by some previous stackoverflow questions.
You can generate models corresponding to your existing tables in the same way as you would for new tables and then use a number of methods to handle places where your existing table and field names don't follow Rails naming conventions. e.g. if you create a Project model then Rails would expect the table to be called projects (plural). If your table was called project you would need to add to your model:
class Project < ActiveRecord::Base
set_table_name "project"
end
Similarly, if the primary key for your table was project_id rather than just id you could do:
class Project < ActiveRecord::Base
primary_key = 'project_id'
end
you can use sql manager to create the database.
rails use sqlite3 by default.
Related
I am using EF core and SQL database in my project. I have data model with several entities (principal with child/dependent ones) and as key I used int IDs. My entities have also defined unique UUID property for other usage. One of the is to identify same entity in test/production environment because primary key is not consistent. That means entity on test server ID=1 is not the same entity on other SQL server with production environment.
I thought using INT ID would be a good performance choice BUT I came to a problem:
I am in need to transfer selected data (entities) from test to production SQL server. My idea was to serialize those entities to JSON via .NET core native serializer from test machine and loading them to production one.
I am able to identify individual entities between enviroments via UUID property, but the problem is with setting relations/navigation between them. Have anyone solved similar issues?
I have an application which is using Entity Framework 6 in order to interact with a SQL Server database. I have several migrations files due to the evolution of the application.
Now, I'd like to add the possibility to choice between a SQL Server database and a PostgreSQL database with keeping the same entity model.
When I apply the migrations files on SQL Server, all is ok.
But when I apply the same migrations files on PostgreSQL, it says that the database does not match the entity model and I have to generate a new migration file.
If I generate a new migration file, I see that it want to remove the property unicode on all string columns. I think it's because on PostgreSQL the type varchar (character varying) is able to store unicode and non unicode characters.
If I apply this migration file on PostgreSQL, all is ok now. But if I apply it on SQL Server, it say that the database does not match the entity model => columns varchar has been replaced per nvarchar.
I thought that the migrations files was able to adapt to the provider but apparently not.
For information, the property unicode is manage like that in the onModelCreating method :
modelBuilder.Entity<MyTable>()
.Property(e => e.ColumnName)
.IsUnicode(false);
So, my question is, do I have to manage different migration files depending on provider, knowing that I want to keep the same entity model ? If yes, how can I do this ?
Thanks a lot for your help
I have found a solution, I'm not sure it's the best but it's working.
In order not to be annoy anymore, I've created a batch migrations files per provider.
For that I've created one configuration per provider with specifying a specific context key and a different folder containing the migrations files.
This permits to switch between the different configurations depending of the current provider.
I have decided to migrate from my CodeIgniter app to laravel specially for their rails-likely handling of the database.
The problem though is that i have 800mb of database to migrate. How can I do this in a good and fast way? The tutorials i have seen is based on old laravel models to new ones. Which makes me confused.
I also use codeigniter's crypt library for the user passwords. How can I migrate this?
Databases are pretty much the same in Laravel or Codeigniter, if your tables are good the way they are for you and they have a primary key named id (this also is not mandatory) you can just connect with Laravel in your database and it will work just fine.
For your new tables, you can create new migrations and Laravel will not complaint about this.
Well, but if you really need to migrate to a whole new database, you can do the following:
1) rename the tables you need to migrate
php artisan migrate:make
2) create all your migrations with your and migrate them:
php artisan migrate
3) use your database server sql utility to copy data from one table to another, it will be way faster than creating everything in Laravel, believe me. Most databases will let you do things like:
INSERT INTO users (FirstName, LastName)
SELECT FirstName, LastName
FROM users_old
And in some you'll be able to do the same using two different databases and columns names
INSERT INTO NEWdatabasename.users (firstName+' '+Lastname, email)
SELECT name, email
FROM OLDdatabasename.
Or you can just export data to a CSV file and then create a method in your Laravel seeding class to load that data into your database, with a lot of data to import, you just have to remember to execute:
DB::disableQueryLog();
So your PHP doesn't run out of memory.
See? There are a lot of options, probably many more, so pick one and if you need help, shoot more questions.
I used Visual Studio 2010, MVC 3 and Entity Framework 4.1 (Database First) to create a web application using an existing database. In other words the structure of the database was used to generate the basic code for the models. I created controllers with "Controller with Read/Write actions and views, using EntityFrameword" as scaffolding option. However, I cannot see the data that was already in my database when I access the web application, and if I insert new data, I can see it using the web application, but I cannot see it in my database. I am now wondering where my web application is fetching and storing its data. It is as if a new database with an identical structure had been created elsewhere, but I don't know where.
By the way, I specified "New Data Context..." as Data Context Class when creating my first controller.
I suppose that you should start create Db (or another one scenerio to create new db and drop ex)
DropCreateDatabaseAlways<OhMyContext> initDb =
new DropCreateDatabaseAlways<OhMyContext>();
And after that
using (OhMyContext context = new OhMyContext())
{
initDb.InitializeDatabase(context);
}
and now you can use your db. it will create SQL server as defined config.
of course you should use your DbSet<T> as collections. but data will be modified (update, delete or insert) after context.SaveChanges().
gl.
I'm new in developing in MVC and I have some doubts in how to build the Models. I don't know if I must build them in terms of Database Tables or in other terms.
I have for example this 5 tables:
Domain
Category_Domains
Countries_Domains
Categories
Countries
How can i Build a Models to do actions in these Database Tables. Should I built the SQL commands to Insert, Delete and Update for each one of these Tables or I should do other thing than this?
Sorry if I not explain well.
The best advice I can give you is to look into the entity framework. Using this framework, you can create a data connection to your SQL database and the framework will create your model based on your table structure, including relationships.
Doing this will ensure your database is modelled correctly and kept in sync at all times