Skip to content

Instantly share code, notes, and snippets.

View danieljohnmorris's full-sized avatar
😀

Daniel Morris danieljohnmorris

😀
View GitHub Profile
@danieljohnmorris
danieljohnmorris / fix postgres key constraint error
Last active January 3, 2016 20:29
postgres - duplicate key violates unique constraint postgresql (i get this error when downloading production rails db to localhost through heroku)
# in psql prompt
# connect to db
\c databasename
# update counter
SELECT setval('tablename_columnname_seq', (SELECT MAX(columnname) FROM tablename)+1);
git config alias.co checkout
git config alias.com commit
git config alias.pu !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
git config alias.mrg '!git commit -m "merge"'
@danieljohnmorris
danieljohnmorris / fetch_upstream.sh
Created January 15, 2014 09:04
git - fetch upstream
git fetch upstream
git merge upstream/master
1) backup production database:
heroku pgbackups:capture --expire --remote production
2) obtain url string to backup from step 1:
heroku pgbackups:url --app production_app_name --remote production_app_branch_name
3) transfer backup from production to staging app:
heroku pgbackups:restore DATABASE 'production_app_backup_url_string_from_step_2' --app production_app_name --app staging_app_branch_name
@danieljohnmorris
danieljohnmorris / migrate_db.sh
Created December 2, 2013 11:03
migrate db heroku postgres
heroku pgbackups:capture -a gsa-live --expire
heroku pgbackups:restore HEROKU_POSTGRESQL_GREEN -a gsa-staging `heroku pgbackups:url -a gsa-live`
@danieljohnmorris
danieljohnmorris / fix_postgres_constraints.sh
Created October 10, 2013 17:33
Postgres.app dev db fix bugged table id constraints
psql -h localhost
\c gsa_development;
REINDEX DATABASE gsa_development;
SELECT MAX(id) FROM taggings;
SELECT nextval('taggings_id_seq');
SELECT setval('taggings_id_seq', (SELECT MAX(id) FROM taggings)+1);
class hey
def hi
if true
end
end
end
@danieljohnmorris
danieljohnmorris / command line
Last active December 18, 2015 01:39
work mode
mate /etc/hosts
*add lines to hosts file / comment out to use sites*
dscacheutil -flushcache
class CreateSearches < ActiveRecord::Migration
def self.up
ActiveRecord::Base.connection.execute <<-SQL
CREATE VIEW searches AS
SELECT authors.id AS searchable_id, authors.name AS term,
CAST ('Author' AS varchar) AS searchable_type
FROM authors
UNION
SELECT books.id AS searchable_id, books.title AS term,
CAST ('Book' AS varchar) AS searchable_type
class Search < ActiveRecord::Base
# We want to reference various models
belongs_to :searchable, :polymorphic => true
# Wish we could eliminate n + 1 query problems,
# but we can't include polymorphic models when
# using scopes to search in Rails 3
# default_scope :include => :searchable
# Search.new('query') to search for 'query'