<p dir="auto"><strong>Migrated issue, originally created by Johannes Erdfelt (<a href="https://github.com/jerdfelt">@jerdfelt</a>)</strong></p>
<p dir="auto">sqlite treats unique indexes and unique constraints as distinct entities. However, only indexes are reflected and unique constraints aren't.</p>
<p dir="auto">This is different than mysql (which aliases unique constraints to a unique index) and postgresql (which has distinct unique indexes and unique constraints).</p>
<p dir="auto">The attached script shows the problem.</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/3184/test_reflection.py">test_reflection.py</a> | <a href="../wiki/imported_issue_attachments/3184/postgres.dump">postgres.dump</a> | <a href="../wiki/imported_issue_attachments/3184/sqlite.dump">sqlite.dump</a></p>
<h3 dir="auto">Describe the use case</h3>
<p dir="auto">Postgresql supports domains using the <a href="https://www.postgresql.org/docs/current/sql-createdomain.html" rel="nofollow"><code class="notranslate">CREATE DOMAIN</code></a> and <a href="https://www.postgresql.org/docs/current/sql-dropdomain.html" rel="nofollow"><code class="notranslate">DROP DOMAIN</code></a> commands. A domain is a data type with additional constraints -- for example, an email address is a specific kind of string, so you can use a domain to define a type that only accepts strings that are correctly formatted as email addresses.</p>
<p dir="auto">I would like to be able to define and manage domains using SQLAlchemy, in the same kind of way that I am already able to define and manage enums with SQLAlchemy.</p>
<h3 dir="auto">Databases / Backends / Drivers targeted</h3>
<p dir="auto">Postgresql only. As far as I can tell, no other database that SQLAlchemy supports, supports domains.</p>
<h3 dir="auto">Example Use</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import sqlalchemy as sa

Email = Domain(
    name=&quot;email&quot;,
    data_type=sa.Text,
    constraint=sa.CheckConstraint(r&quot;VALUE ~ '[^@]+@[^@]+\.[^@]+'&quot;),
)
t1 = sa.Table(
    &quot;table&quot;,
    metadata,
    sa.Column(&quot;id&quot;, sa.Integer, primary_key=True),
    sa.Column(&quot;email&quot;, Email),
)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">sqlalchemy</span> <span class="pl-k">as</span> <span class="pl-s1">sa</span>

<span class="pl-v">Email</span> <span class="pl-c1">=</span> <span class="pl-v">Domain</span>(
    <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">"email"</span>,
    <span class="pl-s1">data_type</span><span class="pl-c1">=</span><span class="pl-s1">sa</span>.<span class="pl-v">Text</span>,
    <span class="pl-s1">constraint</span><span class="pl-c1">=</span><span class="pl-s1">sa</span>.<span class="pl-v">CheckConstraint</span>(<span class="pl-s">r"VALUE ~ '[^@]+@[^@]+\.[^@]+'"</span>),
)
<span class="pl-s1">t1</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Table</span>(
    <span class="pl-s">"table"</span>,
    <span class="pl-s1">metadata</span>,
    <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">"id"</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>, <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>),
    <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">"email"</span>, <span class="pl-v">Email</span>),
)</pre></div>
<h3 dir="auto">Additional context</h3>
<p dir="auto"><em>No response</em></p>