<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel da Rocha</title>
    <description>The latest articles on DEV Community by Daniel da Rocha (@danroc).</description>
    <link>https://dev.to/danroc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F54264%2F96b9948d-e280-46d1-ab4f-88109173711a.png</url>
      <title>DEV Community: Daniel da Rocha</title>
      <link>https://dev.to/danroc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danroc"/>
    <language>en</language>
    <item>
      <title>Postgres RLS and policies: best practices?</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Sun, 08 Dec 2019 05:46:10 +0000</pubDate>
      <link>https://dev.to/danroc/postgres-rls-and-policies-best-practices-4gfb</link>
      <guid>https://dev.to/danroc/postgres-rls-and-policies-best-practices-4gfb</guid>
      <description>&lt;p&gt;I am currently exploring Postgres's Row Level Security and related policies for my project, and have a question about best practices:&lt;/p&gt;

&lt;p&gt;If I have these tables:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;box&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user_id&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;thing&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;big_box_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;name&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I have a &lt;code&gt;select&lt;/code&gt; policy which checks the user_id agains JWT claims. This let's me only select my own boxes.&lt;/p&gt;

&lt;p&gt;Question: What's the best way to prevent users to select &lt;code&gt;things&lt;/code&gt; which do not belong to them?&lt;/p&gt;

&lt;p&gt;As I see it, there are two options:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 1:&lt;/strong&gt; add a &lt;code&gt;user_id&lt;/code&gt; column to &lt;code&gt;thing&lt;/code&gt; and have each item also store its &lt;code&gt;user_id&lt;/code&gt; to be used on policies (same as in &lt;code&gt;box&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 2:&lt;/strong&gt; on the select policy for &lt;code&gt;thing&lt;/code&gt;, add a check on the &lt;code&gt;user_id&lt;/code&gt; of the parent box&lt;/p&gt;

&lt;p&gt;My intuition says option 2 is cleaner, but I wonder how would that go when things get deeper, let's say my things can also have children, then I have to travel back several levels to the parent box within my select policy?&lt;/p&gt;

&lt;p&gt;Any insights are extremely appreciated!!&lt;/p&gt;

</description>
      <category>help</category>
      <category>postgres</category>
    </item>
    <item>
      <title>How to deploy backend apps with Dokku</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Sat, 21 Sep 2019 14:02:14 +0000</pubDate>
      <link>https://dev.to/danroc/how-to-deploy-backend-apps-to-dokku-4eig</link>
      <guid>https://dev.to/danroc/how-to-deploy-backend-apps-to-dokku-4eig</guid>
      <description>&lt;p&gt;I recently moved all my apps from Heroku to a DigitalOcean droplet using Dokku. This centralized things and I saved me a bunch of money. Here is a recipe I follow for each new app to get it up-and-running.&lt;/p&gt;

&lt;p&gt;For clarification, I am an amateur. I build apps for fun, and I am learning as I go. My advice might be flawed, but it works for me, and it might help you as well :)&lt;/p&gt;

&lt;h2&gt;
  
  
  What do I build?
&lt;/h2&gt;

&lt;p&gt;My projects are all built on a Vue-based frontend (either using Vue-CLI, Nuxt, Vuepress, or Gridsome). When I need a database, I set up a Postgres instance with Postgraphile, which gives me a GraphQL endpoint in the backend. Just recently, I started exploring Strapi as an attractive CMS, which also uses Postgres as a database and delivers data to my frontend through a GraphQL endpoint. &lt;/p&gt;

&lt;h2&gt;
  
  
  Where do I host?
&lt;/h2&gt;

&lt;p&gt;For all my frontend needs, Netlify is more than enough. It is free, easy to use, has excellent interface and usability. It is perfect for Vue-powered projects.&lt;/p&gt;

&lt;p&gt;Unfortunately, Netlify won’t work for my backend projects which rely on Postgres. I tried many services but ended up choosing Dokku on DigitalOcean as the best solution all my backend needs. &lt;/p&gt;

&lt;h2&gt;
  
  
  What else have I tried?
&lt;/h2&gt;

&lt;p&gt;Once you start using Postgres in the backend, there are two options: self-hosted or hosted database services. &lt;/p&gt;

&lt;p&gt;For a long time, I thought I had to avoid self-hosting (and self-maintaining) a Postgres database. Sharding? Replication? Backups and restores? Upgrades? It all used to give me chills. &lt;/p&gt;

&lt;p&gt;So I spent most of my early development days trying out hosted database services out there.&lt;/p&gt;

&lt;h3&gt;
  
  
  Heroku
&lt;/h3&gt;

&lt;p&gt;Yes, Heroku has a generous free tier with a free Postgres add-on. &lt;/p&gt;

&lt;p&gt;However, free comes to a cost when you realize you’ll cross some of its limits faster than you think. When you decide to fix all issues and upgrades your services, you are already paying much more than free.&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS RDS
&lt;/h3&gt;

&lt;p&gt;I then moved to AWS RDS, creating a Postgres instance in a container. &lt;/p&gt;

&lt;p&gt;I thought I could host all my databases that for minimal cost, as they offered a very generous free tier. However, once the free tier ended, I was paying almost $50 a month for the database needs of my little side projects. This needed to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Dokku on Digital Ocean?
&lt;/h2&gt;

&lt;p&gt;After a while paying the bill, I realized I was (insert metaphor). Of course, there are advantages of hosted database solutions. However, for the scale of my side projects, I need very little. After all, if something goes wrong and my apps go offline,  I can restore them from backups and get them running again.&lt;/p&gt;

&lt;p&gt;Therefore, my requirements were simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scheduled DB backups&lt;/li&gt;
&lt;li&gt;Easy Git deployments&lt;/li&gt;
&lt;li&gt;Low price&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is where Dokku comes into play. It is just like Heroku, but without the pretty UI. You have to host it on your droplet, and it is all command-line-based. &lt;/p&gt;

&lt;p&gt;However, it offers it all: you can easily create apps, add domains, set variables, add Postgres databases, set up scheduled backups, and deploy via git. &lt;/p&gt;

&lt;p&gt;All in one little Digital Ocean droplet costing me 5USD/month.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s my process?
&lt;/h2&gt;

&lt;p&gt;Every time I start a new app, I follow a series of steps which make the whole process very simple. This recipe assumes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You already have a DO droplet with Dokku installed. If not, &lt;a href="https://github.com/dokku/dokku/blob/master/docs/getting-started/install/digitalocean.md" rel="noopener noreferrer"&gt;follow this tutorial&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You already ensured the safety of your droplet, removing root login and creating a new user who can login via SSH. If not, &lt;a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04" rel="noopener noreferrer"&gt;follow this tutorial&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You logged into your droplet via SSH&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create the app
&lt;/h3&gt;

&lt;p&gt;You can use Dokku by typing &lt;code&gt;dokku&lt;/code&gt; followed by the command and other options. Type &lt;code&gt;dokku help&lt;/code&gt; to see a list of all commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ dokku &lt;span class="nb"&gt;help
&lt;/span&gt;Usage: dokku &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--quiet&lt;/span&gt;|--trace|--rm-container|--rm|--force] COMMAND &amp;lt;app&amp;gt; &lt;span class="o"&gt;[&lt;/span&gt;command-specific-options]

Primary &lt;span class="nb"&gt;help &lt;/span&gt;options, &lt;span class="nb"&gt;type&lt;/span&gt; “dokku COMMAND:help” &lt;span class="k"&gt;for &lt;/span&gt;more details, or dokku &lt;span class="nb"&gt;help&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt; to see all commands.

Commands:

    apps                     Manage Dokku apps
    buildpacks               Manages buildpack settings &lt;span class="k"&gt;for &lt;/span&gt;an app
    certs                    Manage Dokku apps SSL &lt;span class="o"&gt;(&lt;/span&gt;TLS&lt;span class="o"&gt;)&lt;/span&gt; certs
    checks                   Manage zero-downtime settings
    config                   Manages global and app-specific config vars
    docker-options           Pass options to Docker the various stages of an app
    domains                  Manage vhost domains used by the Dokku proxy
    enter                    Connect to a specific app container
    events                   Show the last events &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-t&lt;/span&gt; follows&lt;span class="o"&gt;)&lt;/span&gt;
    git                      Manages the git integration &lt;span class="k"&gt;for &lt;/span&gt;an app
    &lt;span class="nb"&gt;help                     &lt;/span&gt;Print the list of commands
    logs                     Output app logs
    network                  Manages network settings &lt;span class="k"&gt;for &lt;/span&gt;an app
    nginx                    Interact with Dokku’s Nginx proxy
    proxy                    Manage the proxy used by dokku on a per app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, you can also type &lt;code&gt;dokku COMMAND:help&lt;/code&gt; for further help on specific commands. As we want to create an app, let’s check how to use the &lt;code&gt;apps&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ dokku apps:help
Usage: dokku apps[:COMMAND]
Manage Dokku apps

Example:
&lt;span class="nv"&gt;$ &lt;/span&gt;dokku apps:list
&lt;span class="o"&gt;=====&amp;gt;&lt;/span&gt; My Apps
example
example2

Additional commands:
    apps                              &lt;span class="o"&gt;[&lt;/span&gt;DEPRECATED] Alias &lt;span class="k"&gt;for &lt;/span&gt;apps:list
    apps:clone &amp;lt;old-app&amp;gt; &amp;lt;new-app&amp;gt;    Clones an app
    apps:create &amp;lt;app&amp;gt;                 Create a new app
    apps:destroy &amp;lt;app&amp;gt;                Permanently destroy an app
    apps:exists &amp;lt;app&amp;gt;                 Checks &lt;span class="k"&gt;if &lt;/span&gt;an app exists
    apps:list                         List your apps
    apps:lock &amp;lt;app&amp;gt;                   Locks an app &lt;span class="k"&gt;for &lt;/span&gt;deployment
    apps:locked &amp;lt;app&amp;gt;                 Checks &lt;span class="k"&gt;if &lt;/span&gt;an app is locked &lt;span class="k"&gt;for &lt;/span&gt;deployment
    apps:rename &amp;lt;old-app&amp;gt; &amp;lt;new-app&amp;gt;   Rename an app
    apps:report &lt;span class="o"&gt;[&lt;/span&gt;&amp;lt;app&amp;gt;] &lt;span class="o"&gt;[&lt;/span&gt;&amp;lt;flag&amp;gt;]      Display report about an app
    apps:unlock &amp;lt;app&amp;gt;                 Unlocks an app &lt;span class="k"&gt;for &lt;/span&gt;deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Easy to figure out what to do next, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ dokku apps:create appname
&lt;span class="nt"&gt;-----&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Creating appname... &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can, of course, use any name you want. It is the same as creating a new app in Heroku. It also gives you a remote git repository which you can add to your local app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add dokku dokku@&amp;lt;droplet-ip&amp;gt;:appname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the droplet IP in the command above before adding. I am assuming you already use git to deploy apps, so I will not get much into detail on that. If not, check this tutorial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add a domain
&lt;/h3&gt;

&lt;p&gt;I always like to have my backend hosted on a subdomain of my apps. For example, if my app is at &lt;a href="https://awarded.to" rel="noopener noreferrer"&gt;awarded.to&lt;/a&gt;, I want its API endpoint to be at &lt;em&gt;api.awarded.to&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;You do not need to do this (you can always access your app using the droplet’s IP address), but it makes it all clean and friendly. It also helps when you have several apps in the same droplet. Moreover, it is straightforward to do:&lt;/p&gt;

&lt;p&gt;First, you need to modify your domain’s DNS settings. You’ll need to add an &lt;em&gt;A record&lt;/em&gt; named after your subdomain and pointing to the droplet’s IP address. On Netlify, it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4vwpl4zf4b99791mi86z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4vwpl4zf4b99791mi86z.png" alt="Screenshot of Netlify’s DNS records"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The instructions for your registrar might differ. Just search its docs for "add DNS subdomain" and you should find quick answers.&lt;/p&gt;

&lt;p&gt;Now back on Dokku, you’ll add the subdomain to your app. For that, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ dokku domains:add appname domain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The domain should be without the &lt;code&gt;http&lt;/code&gt; protocol (just &lt;em&gt;api.awarded.to&lt;/em&gt; instead of &lt;em&gt;&lt;a href="https://api.awarded.to" rel="noopener noreferrer"&gt;https://api.awarded.to&lt;/a&gt;&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;To keep it all safe and secure, you should also enforce &lt;code&gt;https&lt;/code&gt; on your endpoint. This article walks you through the steps necessary to ensure encryption when accessing your backend endpoint: &lt;a href="https://medium.com/@pimterry/effortlessly-add-https-to-dokku-with-lets-encrypt-900696366890" rel="noopener noreferrer"&gt;Effortlessly add HTTPS to Dokku, with Let’s Encrypt&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Add Postgres
&lt;/h3&gt;

&lt;p&gt;As in Heroku, adding a Postgres service to your app is pretty simple. First, you create a new database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ dokku postgres:create dbname

&lt;span class="c"&gt;# Then link it to your app&lt;/span&gt;
~ dokku postgres:link appname dbname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it. It creates an environment variable called DATABASE_URL with your database address. If your app is configured to access the database via this environment variable, you are good to go. Otherwise, you can set other variables as necessary, based on this value.&lt;/p&gt;

&lt;p&gt;You should also set up automatic backups on your database. I usually set up a cron job to create a database dump every day, and upload it to an AWS S3 bucket. &lt;/p&gt;

&lt;p&gt;For that, you’ll first need both an S3 bucket and an IAM user with the appropriate permissions. Create a bucket on S3 and a user on AWS IAM with the following policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:ListAllMyBuckets"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:GetBucketLocation"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::*"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::lutasanticapital/*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::lutasanticapital"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy its credentials (Access Key ID and Secret access key), which you’ll use to configure the backups on Dokku:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# setup s3 backup authentication&lt;/span&gt;
dokku postgres:backup-auth dbname AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY

&lt;span class="c"&gt;# backup the `appname` service to the `BUCKET_NAME` bucket on AWS&lt;/span&gt;
dokku postgres:backup appname BUCKET_NAME

&lt;span class="c"&gt;# schedule a backup&lt;/span&gt;
&lt;span class="c"&gt;# CRON_SCHEDULE is a crontab expression, eg. "0 3 * * *" for each day at 3am&lt;/span&gt;
dokku postgres:backup-schedule appname CRON_SCHEDULE BUCKET_NAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy and enjoy
&lt;/h2&gt;

&lt;p&gt;That is pretty much it. If your app is not overly complicated, it should be working right after the first git push to the dokku remote:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ git push dokku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep an eye on the log to see if the app deployed correctly and to correct any error that may arise. &lt;/p&gt;

&lt;p&gt;Your app should then be live on your chosen domain, just waiting for your frontend to connect!&lt;/p&gt;

&lt;h2&gt;
  
  
  Help me to improve it
&lt;/h2&gt;

&lt;p&gt;Let me know if you have any questions.&lt;/p&gt;

&lt;p&gt;As I wrote earlier, I am an amateur. Please, if you see mistakes or opportunities for improvement, let me know! I am always happy to learn how to make things better.&lt;/p&gt;

</description>
      <category>deployment</category>
      <category>dokku</category>
    </item>
    <item>
      <title>GraphQL pagination</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Thu, 07 Feb 2019 17:41:44 +0000</pubDate>
      <link>https://dev.to/danroc/graphql-pagination-7fc</link>
      <guid>https://dev.to/danroc/graphql-pagination-7fc</guid>
      <description>&lt;p&gt;I've been playing a lot with GraphQL and Apollo lately, but I am usually unsure about &lt;strong&gt;best practices&lt;/strong&gt; when it comes to querying the server and getting results back. &lt;/p&gt;

&lt;p&gt;Now, say I have a &lt;strong&gt;list of locations&lt;/strong&gt; which I want to display in a &lt;strong&gt;paginated&lt;/strong&gt; list:&lt;/p&gt;

&lt;p&gt;Let's say I decide to use Apollo's &lt;a href="https://www.apollographql.com/docs/react/features/pagination.html"&gt;pagination capabilities&lt;/a&gt; and get 10 locations at a time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If I want to filter by city using a dropdown with all cities in the DB, the paginated results will return me only the cities within those 10 locations. Should I then make a separate query for that (eg.

&lt;code&gt;allCities {...}&lt;/code&gt;

)? &lt;/li&gt;
&lt;li&gt;Then if I select a city as a filter, I should make yet another new query filtered by the city, right?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or should I just ditch Apollo's pagination and query &lt;strong&gt;all&lt;/strong&gt; locations, and do all the pagination and filtering in the &lt;strong&gt;client&lt;/strong&gt;? In that case, how much is too much data for an initial load?&lt;/p&gt;

&lt;p&gt;Or am I missing something?&lt;/p&gt;

&lt;p&gt;Please help!&lt;/p&gt;

&lt;p&gt;Thanks!!&lt;br&gt;
Greetings from Berlin...&lt;/p&gt;

</description>
      <category>help</category>
      <category>graphql</category>
      <category>apollo</category>
    </item>
    <item>
      <title>How do you rank your ranked content?</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Tue, 29 Jan 2019 14:21:48 +0000</pubDate>
      <link>https://dev.to/danroc/how-do-you-rank-your-ranked-content-1c0d</link>
      <guid>https://dev.to/danroc/how-do-you-rank-your-ranked-content-1c0d</guid>
      <description>&lt;p&gt;If you have a website where content is displayed based on user voting/popularity, how do you rank your content and why?&lt;/p&gt;

&lt;p&gt;I am aware of some algorithms, such as Hackernews's and Reddit's, but I am interested in reasons why &lt;strong&gt;you&lt;/strong&gt; chose the right one for &lt;strong&gt;your&lt;/strong&gt; content.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Docker from development to deployment</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Thu, 03 Jan 2019 06:59:34 +0000</pubDate>
      <link>https://dev.to/danroc/docker-from-development-to-deployment-12f8</link>
      <guid>https://dev.to/danroc/docker-from-development-to-deployment-12f8</guid>
      <description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;I've been trying to solve this for days now so I might finally just ask for help:&lt;/p&gt;

&lt;p&gt;In my development docker-compose configuration, I have 4 containers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;front&lt;/strong&gt;: Vue app started using &lt;code&gt;npm run serve&lt;/code&gt; on port 80&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;back&lt;/strong&gt;: Koa2 server for my API (Postgraphile for GraphQL)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;database&lt;/strong&gt;: Postgres container&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;front-balancer&lt;/strong&gt;: Nginx server, sends &lt;code&gt;/&lt;/code&gt; to &lt;strong&gt;front&lt;/strong&gt;, &lt;code&gt;/graphql&lt;/code&gt; to &lt;strong&gt;back&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It works fine locally (although I probably should skip Nginx for development...)&lt;/p&gt;

&lt;p&gt;Now I want to deploy it, and that's where my headaches began. My initial understanding is that I should not use &lt;code&gt;npm run serve&lt;/code&gt; for &lt;strong&gt;front&lt;/strong&gt; on production, but instead build my Vue app and serve the static files with Nginx. &lt;br&gt;
But does that mean I do not need my &lt;strong&gt;front&lt;/strong&gt; container in production and can just mount the built files to my Nginx container?&lt;/p&gt;

&lt;p&gt;Or how would you approach this?&lt;/p&gt;

&lt;p&gt;Then comes the actual deployment. I am still at a loss as to where (DO, Heroku, AWS??) and how to deploy it (CD workflow). But that might come as a later question once I figure out the step above!&lt;/p&gt;

&lt;p&gt;Thanks in advance!&lt;/p&gt;

</description>
      <category>help</category>
      <category>docker</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Static site with markdown pages, but with bits of dynamic content in it? </title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Fri, 26 Oct 2018 12:42:47 +0000</pubDate>
      <link>https://dev.to/danroc/static-site-with-markdown-pages-but-with-bits-of-dynamic-content-in-it--342k</link>
      <guid>https://dev.to/danroc/static-site-with-markdown-pages-but-with-bits-of-dynamic-content-in-it--342k</guid>
      <description>&lt;p&gt;Hello!&lt;/p&gt;

&lt;p&gt;I have long thought about converting &lt;a href="https://theforeignarchitect.com/" rel="noopener noreferrer"&gt;my Wordpress blog&lt;/a&gt; into a &lt;strong&gt;static site&lt;/strong&gt; with all the posts as markdown files, using either Hugo, or Jekyll, or Gridsome, etc.&lt;/p&gt;

&lt;p&gt;However, I have a custom &lt;strong&gt;shortcodes&lt;/strong&gt; in each of my posts which grab data from a database and convert it to elements in the post.&lt;/p&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr9nr56ep7e5w1890o06g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr9nr56ep7e5w1890o06g.png" alt="shortcode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Becomes this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsgkkpe6gvcwkghfbl6jy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsgkkpe6gvcwkghfbl6jy.png" alt="rendered posts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I tried doing some research about how to make this situation work in a static site, but I in a bit of a loss as to where to start.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Would it still work as a static site with bits of dynamic content being called at render time?&lt;/li&gt;
&lt;li&gt;Or would the dynamic content be called at build time only (which would be totally ok as well)?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I thought I'd ask you guys: anyone with similar experiences or tips about this?&lt;/p&gt;

&lt;p&gt;Thanks!&lt;br&gt;
Daniel&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>markdown</category>
      <category>staticsite</category>
    </item>
    <item>
      <title>Do you manage your own Postgres or use a DBaaS?</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Wed, 19 Sep 2018 14:36:41 +0000</pubDate>
      <link>https://dev.to/danroc/do-you-manage-your-own-postgres-or-use-a-dbaas-emh</link>
      <guid>https://dev.to/danroc/do-you-manage-your-own-postgres-or-use-a-dbaas-emh</guid>
      <description>&lt;p&gt;I read here and there some people saying how they want to use a hosted DB service for they Postgres database instead of hosting it on their own VPS. &lt;/p&gt;

&lt;p&gt;I did some research and found interesting solutions such as &lt;a href="https://devcenter.heroku.com/categories/heroku-postgres"&gt;Heroku Postgres&lt;/a&gt;, &lt;a href="https://cloud.google.com/sql/"&gt;Google Cloud SQL&lt;/a&gt;, &lt;a href="https://aws.amazon.com/rds/postgresql/"&gt;Amazon RDS&lt;/a&gt;, &lt;a href="https://www.elephantsql.com/"&gt;ElephantSQL&lt;/a&gt;, &lt;a href="https://compose.com/"&gt;Compose&lt;/a&gt;, etc.&lt;/p&gt;

&lt;p&gt;However, I quickly understood that anything above the free/dev tier could have costs escalate quite quickly. &lt;/p&gt;

&lt;p&gt;So, what to do? is it that hard/problematic to host my own Postgres? &lt;br&gt;
Do you use DBaaS? If so, what do you recommend?&lt;/p&gt;

&lt;p&gt;Thanks!!&lt;br&gt;
Greetings from Berlin!&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>postgres</category>
      <category>hosting</category>
      <category>dbaas</category>
    </item>
    <item>
      <title>Explain Middleware Like I'm Five</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Wed, 05 Sep 2018 14:57:20 +0000</pubDate>
      <link>https://dev.to/danroc/explain-middleware-like-im-five-1agf</link>
      <guid>https://dev.to/danroc/explain-middleware-like-im-five-1agf</guid>
      <description>&lt;p&gt;I'm trying to wrap my head around &lt;strong&gt;servers&lt;/strong&gt; and how to set up one with all the stuff I wanna use on my app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Middlewares&lt;/strong&gt; keep popping up... I guess it is something that gets loaded by the server in the middle of sth?? Please help!&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
      <category>middleware</category>
      <category>server</category>
    </item>
    <item>
      <title>Wanna play with GraphQL on an existing database</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Fri, 24 Aug 2018 11:07:40 +0000</pubDate>
      <link>https://dev.to/danroc/wanna-play-with-graphql-on-an-existing-database-185</link>
      <guid>https://dev.to/danroc/wanna-play-with-graphql-on-an-existing-database-185</guid>
      <description>&lt;p&gt;I spend some time earlier this year building a REST-API for a personal app project (Vue in the frontend, Python + Flask + Postgres for the backend API). It is pretty complex and works fine. My PostgreSQL database if full of data now and all tables are working well together.&lt;/p&gt;

&lt;p&gt;But lately, I've been having the itch to try out &lt;strong&gt;GraphQL&lt;/strong&gt;... just for fun. What would you guys recommend? My app is using Vue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.graphile.org/postgraphile/"&gt;PostGraphile&lt;/a&gt;? seems easy to start with, but will it be sustainable in the long run? &lt;a href="https://akryum.github.io/vue-apollo/"&gt;Apollo&lt;/a&gt;? seems like the "standard" pair to Vue?&lt;/p&gt;

&lt;p&gt;Anyone ever did this, converting a REST API to a GraphQL API?&lt;/p&gt;

&lt;p&gt;Will it really be fun? 🤔&lt;/p&gt;

&lt;p&gt;Thanks!&lt;br&gt;
best,&lt;br&gt;
Daniel&lt;/p&gt;

</description>
      <category>help</category>
      <category>graphql</category>
      <category>postgres</category>
      <category>vue</category>
    </item>
    <item>
      <title>Vue+Flask on DigitalOcean: how to proceed?</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Tue, 19 Jun 2018 06:14:02 +0000</pubDate>
      <link>https://dev.to/danroc/vueflask-on-digitalocean-how-to-proceed-2oid</link>
      <guid>https://dev.to/danroc/vueflask-on-digitalocean-how-to-proceed-2oid</guid>
      <description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;Following my &lt;a href="https://dev.to/danroc/ready-to-deploy-vue--flask-but-where-to-deploy-it-to-57o3"&gt;earlier post&lt;/a&gt;, I am now trying to have my app running on a &lt;strong&gt;single&lt;/strong&gt; Digital Ocean droplet.&lt;/p&gt;

&lt;p&gt;But how should I approach it? &lt;/p&gt;

&lt;p&gt;Is it correct to have my Vue app being served to the outside world and the Flask API being served locally in the droplet, and have my Vue app access it via &lt;code&gt;localhost:port&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Or do I need two server blocks, one for the Vue app and one for the Flask API? &lt;/p&gt;

&lt;p&gt;(the API is for internal use only, I do not intend to have a public endpoint to it)&lt;/p&gt;

&lt;p&gt;Thanks for the help!&lt;br&gt;
Daniel&lt;/p&gt;

</description>
      <category>digitalocean</category>
      <category>flask</category>
      <category>vue</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Ready to deploy! Vue + Flask, but where to deploy it to?</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Mon, 21 May 2018 23:27:30 +0000</pubDate>
      <link>https://dev.to/danroc/ready-to-deploy-vue--flask-but-where-to-deploy-it-to-57o3</link>
      <guid>https://dev.to/danroc/ready-to-deploy-vue--flask-but-where-to-deploy-it-to-57o3</guid>
      <description>&lt;p&gt;Hi all!&lt;/p&gt;

&lt;p&gt;After some weeks toiling with my app, I would love to finally &lt;strong&gt;deploy&lt;/strong&gt; it to a production server. The thing is built as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend: &lt;strong&gt;Python Flask + Postgresql&lt;/strong&gt; as an API endpoint&lt;/li&gt;
&lt;li&gt;Frontend: &lt;strong&gt;Vue.js&lt;/strong&gt; SPA with axios calls to my API to populate data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So where would you put something like this? I am thinking, &lt;em&gt;Heroku&lt;/em&gt; or &lt;em&gt;Digital Ocean&lt;/em&gt;? Or not? Any advice on what should I watch out for?&lt;/p&gt;

&lt;p&gt;As much as the idea of a static site is appealing (using nuxt.js or VuePress), it would not work for me, as I have a lot of relational data that might be displayed by the user in unpredictable ways. Also, there will be a user account system on v2.0, so I guess this disqualifies the site for &lt;em&gt;Netlify&lt;/em&gt;, right?&lt;/p&gt;

&lt;p&gt;Thanks a lot!&lt;br&gt;
Best,&lt;br&gt;
Daniel&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>deployment</category>
      <category>vue</category>
      <category>flask</category>
    </item>
    <item>
      <title>vue/vuex - confused about when to load state</title>
      <dc:creator>Daniel da Rocha</dc:creator>
      <pubDate>Tue, 24 Apr 2018 04:09:53 +0000</pubDate>
      <link>https://dev.to/danroc/vuevuex---confused-about-when-to-load-state-3k37</link>
      <guid>https://dev.to/danroc/vuevuex---confused-about-when-to-load-state-3k37</guid>
      <description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;I have been learning Vue recently, and I love it. However, I have a nagging question.&lt;/p&gt;

&lt;p&gt;I have all my data being called from the server via API calls (axios + Flask-RESTful). &lt;/p&gt;

&lt;p&gt;I could load all my store modules with all the data from the server at once, and then filter it as needed in my views (one "big" API call). Or I could load only the filtered data as needed (multiple API calls, filling the stores with specific data each time).&lt;/p&gt;

&lt;p&gt;What would you do?&lt;/p&gt;

&lt;p&gt;My first reaction was to load from the server as needed in the views, but then I get trouble on reload when the data is not loading and I have to go back and forth in my router links to reload the store...&lt;/p&gt;

&lt;p&gt;Any tips are appreciated!! &lt;br&gt;
Greetings from Beijing&lt;br&gt;
Daniel&lt;/p&gt;

</description>
      <category>vue</category>
      <category>vuex</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
