简体   繁体   English

Vitess:使用 SQL 文件初始化密钥空间架构

[英]Vitess: Initialize keyspace schema using SQL file

I am using helm and the file 101_initial_cluster.yaml from the Vitess example to setup my initial cluster.我正在使用 helm 和 Vitess 示例中的文件101_initial_cluster.yaml来设置我的初始集群。 The example has a schema initialization using SQL string as shown below:该示例使用 SQL 字符串进行架构初始化,如下所示:

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)
          );

I would like to replace this with a file initial: my_initial_keyspace_schema.sql .我想用文件initial: my_initial_keyspace_schema.sql替换它initial: my_initial_keyspace_schema.sql From the Vitess documentation I can see Vitess does allow for this using ApplySchema -sql_file=user_table.sql user , but I would like to initialize using the helm file.从 Vitess 文档中,我可以看到 Vitess 确实允许使用ApplySchema -sql_file=user_table.sql user进行此ApplySchema -sql_file=user_table.sql user ,但我想使用 helm 文件进行初始化。

This would be very helpful as it is very tedious to organize and paste the schema as a string .这将非常有用,因为将模式组织和粘贴为string非常繁琐。 Tables that depend on others have to be pasted first and the rest follow.必须先粘贴依赖于其他人的表格,然后再粘贴其他表格。 Forgetting makes Vitess throw an error.遗忘会使 Vitess 抛出错误。

Welcome to StackOverflow.欢迎使用 StackOverflow。

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.恐怕没有开箱即用的功能可以在 Vitess Helm 图表的当前状态下直接从 SQL 文件初始化 DbSchema。 You can identify any of its configurable parameters via helm inspect <chart_name> command.您可以通过helm inspect <chart_name>命令识别其任何可配置参数。

However, you can try customizing it to match your needs in following ways:但是,您可以尝试通过以下方式自定义它以满足您的需求:

  1. Stay with ApplySchema {-sql=} mode保持 ApplySchema {-sql=} 模式

    but let the SQL schema be slurped from static file as a part of Helm chart template但让 SQL 模式从静态文件中作为 Helm 图表模板的一部分
    (eg from static/initial_schema.sql location): (例如来自static/initial_schema.sql位置):

    So just add a piece of control flow code like this one:所以只需添加一段这样的控制流代码:

 {{ 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 }}

Check more on using Helm built-in Objects like File here此处查看有关使用 Helm 内置对象(如 File)的更多信息

  1. Use ApplySchema {-sql-file=} mode使用 ApplySchema {-sql-file=} 模式

    Adapt a piece of code here , where vtctlclient command is constructed. 此处修改一段代码,其中构造了 vtctlclient 命令。
    This would require also to introduce a new Kubernetes Volume object ( nfs or Git repo based are good options here), which you could mount on Job, under specific path, from where initial_schema.sql file would be used.这还需要引入一个新的 Kubernetes Volume 对象(此处基于nfsGit 存储库是不错的选择),您可以挂载在 Job 上的特定路径下,从这里使用 initial_schema.sql 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM