title: How to model an enum of String based static Ids in Scala?
body: <p>let's say I have a reference data table <code>roles</code> filled with all roles that a user might be granted. The rows are quite stable, meaning that it's uncommon that someone adds a new role to the table. Additionally there's a <code>users</code> table and a join-table <code>users_roles</code>. In fact, the <code>roles</code> table is just required to grant a user some predefined roles by adding a record to <code>users_roles</code>.</p>
  
  <p>The <code>roles</code> table is quite simple:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE IF NOT EXISTS admin.roles (
    id          CHAR(16) PRIMARY KEY,
    description VARCHAR(256) NOT NULL
  );
  </code></pre>
  
  <p>The following example describes a role:</p>
  
  <pre class="lang-sql prettyprint-override"><code>INSERT INTO admin.roles VALUES('CS_AGENT', 'A customer service agent');
  </code></pre>
  
  <p>Obviously, I need the possible <code>id</code> values somewhere in my code. This is a set of Strings, but I'd like to prevent magic Strings and make this more type safe.</p>
  
  <p>As far as I understand, there are several options:</p>
  
  <ul>
  <li>create a symbol for each role id</li>
  <li>create a new type <code>RoleId</code> that extends <code>String</code> and declare vals</li>
  </ul>
  
  <p>In order to define the set of role ids, these are my options:</p>
  
  <ul>
  <li>use an <code>Enumeration</code></li>
  <li>use a sealed trait/sealed object and derive case objects from it</li>
  </ul>
  
  <p>I'm using JOOQ for my persistence layer, and it would be nice if I could use the type safe RoleId in my queries without manually converting it to String and vice versa.</p>
  
  <p>What would be the best solution for this ?</p>