<?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: Jaden Lemmon</title>
    <description>The latest articles on DEV Community by Jaden Lemmon (@jadenlemmon).</description>
    <link>https://dev.to/jadenlemmon</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%2F572951%2F00d1ad24-397d-4beb-a968-50399700b228.jpeg</url>
      <title>DEV Community: Jaden Lemmon</title>
      <link>https://dev.to/jadenlemmon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jadenlemmon"/>
    <language>en</language>
    <item>
      <title>You should embrace database seeding</title>
      <dc:creator>Jaden Lemmon</dc:creator>
      <pubDate>Thu, 25 Feb 2021 03:45:00 +0000</pubDate>
      <link>https://dev.to/jadenlemmon/you-should-embrace-database-seeding-2jd9</link>
      <guid>https://dev.to/jadenlemmon/you-should-embrace-database-seeding-2jd9</guid>
      <description>&lt;h4&gt;
  
  
  Opinionated thoughts on why you should build a process around keeping your development environment seeded with randomized data automatically.
&lt;/h4&gt;

&lt;p&gt;When you embark on a new web application, you should consider building seeders for test data in your local and development environments. Maybe this is a concept that you already know and are familiar with. Maybe you have never used anything like this at all.&lt;/p&gt;

&lt;p&gt;I think we can all relate to the scenario of when we are trying to set up our local environment for a project and then realize the database is empty and there is no data to work with to start developing a new feature. So then we reach out to our team and ask for a database dump and one of our friends slacks it to us. We then import it into our local environment and then go about our day developing a feature.&lt;/p&gt;

&lt;p&gt;This concept may have worked for you initially but then what happens once someone on your team modifies the database schema rendering your current dataset obsolete. Now you must start this whole process over again and retrieve a new dump. &lt;/p&gt;

&lt;p&gt;While this is just one pain point of not using seeders, let me explain all the benefits and maybe there are some that could be useful to you during your development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Streamline Local Development
&lt;/h3&gt;

&lt;p&gt;When using seeders, I will commonly configure an application to run seeders automatically in local development, reducing the need to reach out for database dumps or instructions on building a local database. I am a big believer in empowering your team to write quality code instead of spending time building environments. When your database schema is updated it will force developers to update the seeder alongside it causing test breakage if they don’t.&lt;/p&gt;

&lt;p&gt;How long does it typically take a new developer to onboard onto the application you are working on? I’ve seen days pretty commonly. How much time is reduced if your entire environment can be built with a single command like &lt;code&gt;npm start&lt;/code&gt;? &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Consistent Schema Validation
&lt;/h3&gt;

&lt;p&gt;When using seeders, you can then build the seeding into your CI process testing the construction of your database and that it accepts the seeded dataset without error. This allows initial validation around your database schema and that no developer has altered it in a way to cause unintended side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing
&lt;/h3&gt;

&lt;p&gt;When writing tests for particular features, you commonly will need a populated database to run a proper test. Let’s say I need to test the retrieval of an endpoint containing “projects”. &lt;/p&gt;

&lt;p&gt;For example, the Laravel framework has coined the term “Factory” as a way to create a model instance with test data. I can easily create a few projects for my test like&lt;br&gt;
&lt;code&gt;Project::factory()-&amp;gt;count(3)&lt;/code&gt;;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Random but consistent data set
&lt;/h3&gt;

&lt;p&gt;In production, users are most likely able to enter their values that will be propagated into your database. If you are using the same dataset for local development and testing you are never testing other values through your application which would result in edge case errors in production depending on what kind of logic is being used on those values. &lt;/p&gt;

&lt;p&gt;When creating seeders I can utilize a library like faker to randomize the values in the columns. Every time I seed my database with these random values it allows me to test my database in a similar environment to production where users can enter their values. If an edge case existed to trigger an application error because of content you are increasing the likelihood of triggering such error in development. &lt;/p&gt;

&lt;h3&gt;
  
  
  Easy to create isolated environments for testing features
&lt;/h3&gt;

&lt;p&gt;It’s easy to use with a tool like &lt;a href="https://voyageapp.io/?utm_source=devto&amp;amp;utm_medium=article-link&amp;amp;utm_campaign=blog-posts"&gt;Voyage&lt;/a&gt; where you can deploy on-demand isolated environments to test your new features under development. Let’s say you are working on updating the database schema while you develop a feature. You do not want to keep pushing iterations to your development/staging environment making several database changes during this process. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://voyageapp.io/?utm_source=devto&amp;amp;utm_medium=article-link&amp;amp;utm_campaign=blog-posts"&gt;Voyage&lt;/a&gt; will spin up an entirely new and isolated environment with every commit on every PR which means the database starts fresh with your seeders every time a new commit is pushed. This allows you to continually make database alterations that will not dirty up other environments. &lt;/p&gt;

&lt;h3&gt;
  
  
  Using Frameworks
&lt;/h3&gt;

&lt;p&gt;Most well-known language frameworks provide built-in seeder functionality out of the box. Here are some helpful links to each one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://laravel.com/docs/8.x/seeding"&gt;PHP / Laravel Seeders&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://knexjs.org/#Seeds-CLI"&gt;Express / Knex.js Seeders&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/2.0/howto/custom-management-commands/"&gt;Python / Django Management Commands&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://guides.rubyonrails.org/v5.0.0.1/active_record_migrations.html#migrations-and-seed-data"&gt;Ruby / Rails Seeders&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>productivity</category>
      <category>programming</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Dev Deployments for a Full-Stack App in Minutes</title>
      <dc:creator>Jaden Lemmon</dc:creator>
      <pubDate>Wed, 03 Feb 2021 17:44:59 +0000</pubDate>
      <link>https://dev.to/jadenlemmon/dev-deployments-for-a-full-stack-app-in-minutes-49p3</link>
      <guid>https://dev.to/jadenlemmon/dev-deployments-for-a-full-stack-app-in-minutes-49p3</guid>
      <description>&lt;h3&gt;
  
  
  Creating feature deployments in Voyage for our Node, React, Postgres app.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://ahoy-voyag-shipf-featupdate-t-gddpy.qa.voyageapp.io"&gt;Live demo deployment&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voyage makes it super easy to deploy a full stack application to a demo environment quickly. The only time required is typically the initial integration of Voyage into your application.&lt;/p&gt;

&lt;p&gt;I’m going to reference an example application called &lt;a href="https://github.com/voyage-playground/shipfinder"&gt;ShipFinder&lt;/a&gt;. This app consists of a Node.js API, Create React App Front-End and Postgres database. This application is contained in a single monorepo. Voyage does allow multi-repo deployments but it does streamline the development process with a single repo. See &lt;a href="https://voyageapp.io/docs/voyage-configuration/#MultiRepoConfiguration"&gt;multi-repo deploy docs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Docker
&lt;/h2&gt;

&lt;p&gt;If you are already using Docker within your project, you're already a step ahead. Voyage runs docker images similar to how you may have seen in a docker-compose.yml file. Each service runs in it’s own image. For most applications you will have a “primary” image that is built that contains your application code.&lt;/p&gt;

&lt;p&gt;We will start by creating a Dockerfile in the root of our project that contains code to build our app. Since this is a Node project I will use a Node image. You may use a different Node version then what I have chosen.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Voyage does provide some presets for building simple applications. When using a preset you don’t need to have a Docker container. Only if you are building a more custom application. See the &lt;a href="https://voyageapp.io/docs/voyage-configuration/#UsingDefinedPresets"&gt;documentation&lt;/a&gt; for more information on presets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Voyage Configuration
&lt;/h2&gt;

&lt;p&gt;Now that we have this file we will begin to craft our Voyage config file. We will add a service for our “primary” image containing our app. All config files should begin with the “services” key at the top. Similar to how a docker-compose file may look.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
 app:
   context: ./
   primary: true
   exposePort: 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I will then expand a little bit to add some environment variables to pass to the application. These environment variables are also passed as build arguments while building the primary Docker container as well.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
 app:
   context: ./
   primary: true
   exposePort: 3000
   environment:
     - name: APP_ENV
       value: 'voyage'
     - name: NODE_ENV
       value: 'production'
     - name: DB_HOST
       value: 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now we will need one more service for this particular deployment. A Postgres database. It’s simple to add this as I can just pull the standard postgres docker image in like so.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;database:
   image: postgres:13
   environment:
     - name: POSTGRES_USER
       value: 'voyage'
     - name: POSTGRES_PASSWORD
       value: 'voyage'
     - name: POSTGRES_DB
       value: 'voyage'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You may want to store some of these environment variables as sensitive values through the Voyage UI. You may then reference them in the config file. See &lt;a href="https://voyageapp.io/docs/voyage-configuration/#EnvironmentVariables"&gt;environment variables documentation&lt;/a&gt; for more information.&lt;/p&gt;
&lt;h2&gt;
  
  
  Full Config File
&lt;/h2&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;After creating this config, your project is set to build and teardown environments on every pull request on demand. There is nothing else you need to do besides ensure this repository is enabled in Voyage!&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting Project
&lt;/h2&gt;

&lt;p&gt;To connect your repository for on demand deployments, navigate to the “Providers” tab in the Voyage UI and ensure your git provider organization is added and press “Configure Connected Repos”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_YuFhvcP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.voyageapp.io/videos/repo_connect.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_YuFhvcP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.voyageapp.io/videos/repo_connect.gif" alt="Repo Connect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then just press “Connect with Voyage” on the repo you would like to connect and select “Manual” for this project. Now your repo is connected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;Checkout our blog for more posts like these and our &lt;a href="https://voyageapp.io/docs/voyage-configuration"&gt;documentation&lt;/a&gt; for additional help configuring your projects.&lt;/p&gt;

</description>
      <category>tooling</category>
      <category>saas</category>
      <category>devops</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
