Database Specific Migration Code [duplicate]
问题 This question already has answers here : How do I check the Database type in a Rails Migration? (5 answers) Closed 4 years ago . I'm creating an application that needs to run under multiple databases. I currently have some code in a migration that I only want run under specific databases (postgresql and mysql). Any way of setting this up? Thanks. 回答1: Your migration has access to a database connection in connection and the connection has an adapter_name method so you can just ask it what sort