Today I Learned

15 posts by bartłomiejdanek

PosgreSQL "DROP DATABASE.." RTFM

I have had over 200 databases to move from server to a new one. When a testing “import” succeeded I was ready for a final-final production move.

But I had to clean up the server first and remove all existing databases from “the testing” stage, I even created a SQL function:

DO $$ DECLARE
    db RECORD;
BEGIN
    FOR db IN (SELECT datname FROM pg_database where datdba != 10 AND datdba != 16385 LOOP
        EXECUTE 'DROP DATABASE IF EXISTS ' || quote_ident(db.tablename) ;
    END LOOP;
END $$;

but it did not work as PostgreSQL does not allow to drop a database from a function 😂

Finally, I’ve used a shell script to trigger DROP DATABASE.

Validate privateKey, certificate and CSR files

$ openssl pkey -in privateKey -pubout -outform pem | sha256sum
# => f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2  -
$ openssl x509 -in certificate -pubkey -noout -outform pem | sha256sum 
# => f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2  -
openssl req -in CSR -pubkey -noout -outform pem | sha256sum
# => f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2  -

When all pairs match, you can be sure that you have the right set of files for your domain.

Arel basic use case

veg = Arel::Table.new(:vegetables)

query = veg[:created_at].gteq( 5.days.ago ).and(
  veg[:color].eq("green").or(
    veg[:gardener].eq("Susan")
  )
)

query.to_sql
#  "vegetables"."created_at" >= '2016-12-13 03:54:28.575342'
#    AND ("vegetables"."color" = 'green' OR "vegetables"."gardener" = 'Susan')

Vegetable.where( query )

Triggered by birthday-cake-top-consumer!

Custom nginx proxy host name

server {
    listen 80 default_server;
    server_name ~^(?<developer>.+)\.dev\.selleo\.com$;
    client_max_body_size 5M;
    root   /usr/share/nginx/html;

    location / {
      resolver 8.8.8.8;
      set $backend https://$developer-secret.app.selleo.com:443;
      proxy_pass $backend;
      proxy_set_header  X-Real-IP       $remote_addr;
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

resolver does the job here!