Created
July 27, 2012 21:52
-
-
Save robbkidd/3190645 to your computer and use it in GitHub Desktop.
Quick method to display the names of your PostgreSQL tables and their pkeys and sequences.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_table_and_sequence_names | |
connection = ActiveRecord::Base.connection | |
if connection.adapter_name == "PostgreSQL" | |
table_names = connection.tables.keep_if { |t| t !~ /schema_migrations/ } | |
table_names.map { |t| [t, connection.pk_and_sequence_for(t)].flatten } | |
end | |
end | |
check_table_and_sequence_names | |
# => [["tablename", "primarykeyname", "sequencename"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment