How to delete database attribute?

I made a database with rails generate model User password:string …
now I want to delete the password attribute, because I’m going to
encrypt it
before saving, so I want to make an attribute with name
encrypted_password
instead of password.
How can I do that without deleting the whole file of migration and
making
all from scratch?

Thank you

On Tue, Jun 7, 2011 at 9:25 AM, Rodrigo R.
[email protected]wrote:

I made a database with rails generate model User password:string …
now I want to delete the password attribute, because I’m going to encrypt
it before saving, so I want to make an attribute with name
encrypted_password instead of password.
How can I do that without deleting the whole file of migration and making
all from scratch?

you can do this by creating a *NEW *migration like

add_column :users, :encrypted_password, :string

insert here the steps that will convert password to encrypted_password

remove_column :users, :password

or use devise/authlogic.

Thank, one more thing, is there a way to alter only the original
migration
so all the attributes stay listed in the same file and that can be
easily
altered?

Rodrigo R. wrote in post #1003601:

Thank, one more thing, is there a way to alter only the original
migration
so all the attributes stay listed in the same file and that can be
easily
altered?

Yes, rollback before the migration change for the model and just alter
the migration file itself and make it appear the way you want it to.
Then rake db:migrate. I like my code to be clean as well. The only
reason to add additional columns to an existing table without rolling
back is when your table contains a lot of data that you don’t want to
lose. If you are just developing and have basic seed data populating
the DB, there’s no negative impact polishing up your migration files.

I’m working alone o this project so it won’t be a problem.
How can I do that? I mean, drop the database?
I did change the migration, but when I rake db:migrate, the schema just
gets
back to what it was (I edited the schema too)

On Tue, Jun 7, 2011 at 10:47 AM, Rodrigo R.
[email protected]wrote:

Thank, one more thing, is there a way to alter only the original migration
so all the attributes stay listed in the same file and that can be easily
altered?

The best practice would be to create a new migration everytime you want
to
change the
database structure.

Sure, you can edit the previous migrations but you have to drop your
database before you
can run the migration. Also, editing a migration will cause lots of
confusion if it’s already
pushed to the remote repository and some other developers have already
ran
them.

encrypted_password instead of password.

To post to this group, send email to [email protected]
visit my blog at http://jimlabs.heroku.com


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

If you want to revert back to the beginning and polish up all of your
migrations, just run rake db:migrate VERSION=0 and after you polish up
the migrations the way you want them to look, run rake db:migrate.

Forget it, I just did what you said and it worked =)
thank you very much

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs