I'm using Symfony with Propel ORM v.1.3. I need to change table schema in task, remove few columns exactly. How can I do that? I saw method addColumn in TableMap class, but there was no removeColumn or deleteColumn method.
If you want to remove a column you have to change the schema.xml and then migrate your database.
IMHO the Propel ORM isn't designed to add or remove columns programmatically. The addColumn function in the TableMap class isn't either. So it would be best if your task would somehow automate the steps described in the above mentioned documentation for migrations.
Related
Is it possible to setup Aqueduct ORM to use underscored names for database columns (so if I have field "someField" in model class it will be stored as "some_field" in the database)? Or may be it is at least possible to override column name by some annotation? I have legacy database schema with underscored names and I cannot change it).
This is not supported yet, as of May 2020. Please upvote the associated Github issue.
How can I write a migration for add a column to an existing table? It is easy to do with ActiveRecord but I am confused with DataMapper, please help.
Check out the datamapper documentaion for auto_upgrade. You'll find that most simple updates to your model will be easily handled. For more complex model changes check out dm-migrations.
I have a previously separately managed sql file containing rather simple but large database. Would there be a way to import this sql file and generate ruby code as models using this data as a starting point for my future development?
Thank you for your help!
Yes!
It will take some work!
And you'll need to post a WHOLE HELL OF A LOT more detail to get more than that. ;-)
Taking a stab:
Rails can use legacy databases with a lot of effort manually specifying foreign key columns, table names, etc. It can be done. My suggestion, though, would be to convert the data in-place in whatever database you have by using a lot of ALTER TABLE RENAME... work and same for columns to make the old DB conform to Rails' convetions (primary key == 'id', table name is plural underscore'd version of model name, all that) before doing the import, and then you can just use plain vanilla ActiveRecord and all will be easy.
I'm struggling with the connection/relation from the main class/table to a related class in symfony 1.4 with doctrine. The relation is
$relatedClass->identifier == 'e'.$mainClass->id;
I know that I could realise it easily without this prefix but I am working with an existing database and existing subcomponent, so I can't change this relation.
Any ideas? Thanks!
You cannot implement this is a relation in Doctrine because it is not a true foreign key.
If you cannot change the existing column, is it possible to create a new column? If so, write a migration to add a column to the relatedClass table with a proper foreign key relationship.
I finally made a 'pseudo relation' like this:
$results = Doctrine::getTable($relatedClass)
->createQuery('alias')
->addWhere('alias.identifier=?','e'.$event->getId())
->execute();
It has several advantages:
no changes of the existing tables necessary
no adding of a useless column to a already huge database
It is not elegant but it is the solution with the most advantages so far.
For instance, when I generate an Event model, the table automatically sets to the public schema. How do I specify it to get set to a different schema?
Furthermore, how do you alter the schema of an existing table? Perhaps move it to a different schema?
Thank you!
Disclaimer: I don't know rails, so I'm going to give very postgresql-oriented answers here. For the first part of your question, there is quite possibly a much better way to do this, by making rails specify the schema when creating tables.
In PostgreSQL, tables are searched for in schemas according to the search_path setting. This is set by default to "$user",public. Tables are created in the first schema found in the search path that exists. So if you connect as "my_user", it will try to create tables in "my_user", and fall back to creating them in "public" if "my_user" doesn't exist.
So one approach is to update the "search_path" setting used for the user you connect to the database to make schema changes. For example you can say ALTER USER my_user SET search_path = my_app, public. If you then create a "my_app" schema then subsequent CREATE TABLE foo(...) commands executed by "my_user" will put the new table into "my_app".
You can change the schema of a table using ALTER TABLE foo SET SCHEMA my_app.
Create a migration to generate your new schema. ActiveRecord can't update you schema to you it's the pattern system. You can try sequel or DataMapper if you want update you schema from your code.