Posts

Showing posts from February, 2017

Rails Musings

The order of mentioning stuff in the model.rb files should be: =begin 1. reference to libraries 2. has many association 3. has many through association 4. belongs_to association 5. validations 6. call backs 7. custom validations 8. custom instance methods 9. custom class methods 10. all our private methods =end Oh and btw, =begin and =end mark the start and end of the comment :)

Linux-Postgres Musings

To take a dump from linux server and compress it psql -U username -F filename psql -U postgres -d postgres -f chameli.sql pg_dump -U postgres postgres -f  /tmp/chameli.sql tar -cvzf abc.tar.gz chameli.sql tar -zcvf archive-name.tar.gz directory-name To use a dump file to setup db in win machine  Use pg_restore.exe --host "localhost" --port "5432" -U "postgres" --dbname "postgres" --verbose --schema "public" "C:\Users\abhinav\Downloads\new03march.backup"

SQL Musings

SELECT distinct "public".task."id", "public".task_log.created_at FROM "public".task , "public".task_log WHERE "public".task.actor_id = 777 and task."id"= task_log.task_id order by "public".task_log.created_at desc limit 10 TO Set up data for the whole column UPDATE schema.table_name SET column_name='value' Deleting a lesson SELECT id FROM cmsession WHERE cmsession.title like '%elete%' DELETE FROM cmsession WHERE cmsession.title like '%elete%' SELECT * FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' ) DELETE FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' ) SELECT * from assessment where lesson_id in (SELECT "id" FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' )) DELETE fro