<p>I am using helm and the file <a href="https://github.com/vitessio/vitess/blob/master/examples/helm/101_initial_cluster.yaml" rel="nofollow noreferrer">101_initial_cluster.yaml</a> from the Vitess example to setup my initial cluster. The example has a schema initialization using SQL string as shown below:</p>

<pre><code>schema:
        initial: |-
          create table product(
            sku varbinary(128),
            description varbinary(128),
            price bigint,
            primary key(sku)
          );
          create table customer(
            customer_id bigint not null auto_increment,
            email varbinary(128),
            primary key(customer_id)
          );
          create table corder(
            order_id bigint not null auto_increment,
            customer_id bigint,
            sku varbinary(128),
            price bigint,
            primary key(order_id)
          );
</code></pre>

<p>I would like to replace this with a file <code>initial: my_initial_keyspace_schema.sql</code>. From the Vitess documentation I can see Vitess does allow for this using  <code>ApplySchema -sql_file=user_table.sql user</code>, but I would like to initialize using the helm file.</p>

<p>This would be very helpful as it is very tedious to organize and paste the schema as a <code>string</code>. Tables that depend on others have to be pasted first and the rest follow. Forgetting makes Vitess throw an error. </p>

<p>Welcome to StackOverflow.</p>

<p>I'm afraid there is no out-of-the-box feature to enable initializing DbSchema directly from SQL file in the current state of Vitess Helm chart. You can identify any of its configurable parameters via <code>helm inspect &lt;chart_name&gt;</code> command.</p>

<p>However, you can try customizing it to match your needs in following ways:</p>

<ol>
<li><p>Stay with ApplySchema {-sql=} mode<br><br>
but let the SQL schema be slurped from static file as a part of Helm chart 
template<br> (e.g. from <em>static/initial_schema.sql</em> location):</p>

<p>So just add a piece of control flow code like this one:</p></li>
</ol>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>{{ if .Values.initialSchemaSqlFile.enabled }}
        {{- $files := .Files }}
        {{- range tuple "static/initial_schema.sql" }}
        {{ $schema := $files.Get . }}
{{- end }}
{{ else }}
   # Default inline schema from Values.topology.cells.keyspaces[0].schema
{{ end }}</code></pre>
</div>
</div>
</p>

<p>Check more on using Helm built-in Objects like File <a href="https://helm.sh/docs/chart_template_guide/#glob-patterns" rel="nofollow noreferrer">here</a></p>

<ol start="2">
<li>Use ApplySchema {-sql-file=} mode<br><br>
Adapt a piece of code <a href="https://github.com/vitessio/vitess/blob/d4176b97bcd95072ae452c399d90e4eefe135273/helm/vitess/templates/_keyspace.tpl#L79" rel="nofollow noreferrer">here</a>, where vtctlclient command is constructed.<br>
This would require also to introduce a new Kubernetes Volume object (<a href="https://github.com/kubernetes/examples/blob/master/staging/volumes/nfs/nfs-pv.yaml" rel="nofollow noreferrer">nfs</a> 
or <a href="https://stackoverflow.com/questions/53683594/how-to-clone-a-private-git-repository-into-a-kubernetes-pod-using-ssh-keys-in-se?noredirect=1&amp;lq=1">Git</a> repo based are good options here), which you could <a href="https://kubernetes.io/docs/concepts/storage/volumes/#example-pod-2" rel="nofollow noreferrer">mount</a> on 
Job, under specific path, from where initial_schema.sql file would be used.</li>
</ol>
