Skip to content

Instantly share code, notes, and snippets.

@robbkidd
Created July 27, 2012 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbkidd/3190645 to your computer and use it in GitHub Desktop.
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.
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