<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chen-Che Huang on Medium]]></title>
        <description><![CDATA[Stories by Chen-Che Huang on Medium]]></description>
        <link>https://medium.com/@acmicrox?source=rss-d9192ff4a153------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*y-uk286vNcooccKm1dttRQ.jpeg</url>
            <title>Stories by Chen-Che Huang on Medium</title>
            <link>https://medium.com/@acmicrox?source=rss-d9192ff4a153------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:38:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@acmicrox/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Realize asynchronous Slack slash command with AWS serverless]]></title>
            <link>https://acmicrox.medium.com/realize-asynchronous-slack-slash-command-with-aws-serverless-bb0d4110f436?source=rss-d9192ff4a153------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb0d4110f436</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <category><![CDATA[slackbot]]></category>
            <dc:creator><![CDATA[Chen-Che Huang]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 17:07:21 GMT</pubDate>
            <atom:updated>2020-04-11T23:32:01.110Z</atom:updated>
            <content:encoded><![CDATA[<p>Slack is one of the most popular team collaboration software nowadays. Besides instant messaging, Slack provides many apps and supports custom apps to fulfill various requirements. To invoke a custom app, one entry point is <strong>slash commands</strong> that enable users to run the custom app by simply typing a string on a channel. Explicitly, what a slash command does is to send an HTTP request with the user input to the web endpoint of the associated custom app. Slash commands empower users to accomplish a variety of tasks on Slack channels as long as the corresponding web apps are well implemented.</p><h4>Service deployment as an example</h4><p>In this post, I’d like to introduce how to create a slash command to deploy new versions of services on AWS ECS. Taking service deployment as an example is because it’s common for software engineers. Although deployment should be done via CI/CD tools (e.g., Gitlab CI/CD and Jenkins), using the slash command has two main benefits.</p><ol><li>The deployment actions and results are visible to and traceable for all the stakeholders.</li><li>The deployment is more convenient. Developers can do deployment/rollback easily by simply typing a few words on their mobile phones. QA are able to do the deployment to verify issues with specific versions when necessary without understanding the CI/CD tools.</li></ol><p>Before proceeding, I’d like to remind that this example is for demonstration and is probably useful in the development or staging environment. However, <strong>I don’t suggest to adopt this approach to the production environment</strong>.</p><p>To realize this feature, we need to create a slash command and a web application with permissions to run the deployment. Creating a slash command is fairly simple by following Slack’s <a href="https://api.slack.com/interactivity/slash-commands#creating_commands">guide</a>. Assume we create a slash command named /ecs_deploy with two parameters &lt;service&gt; and &lt;version&gt;. When a user runs/ecs_deploy &lt;service&gt; &lt;version&gt; on a channel, the corresponding web app shall start to update &lt;service&gt; with version and return the result to the same channel.</p><p>Because the slash command is for people instead of bots, it’s ideal to implement this web app with AWS serverless services because 1) the usage frequency is low and 2) performance and latency are not a concern. AWS serverless enables developers to run the applications without managing or operating the underlying infrastructure. With AWS serverless, we don’t need a long-running ec2 instance (which is idle most of the time) and just pay for what we really use. If you haven’t heard of AWS serverless, you may take a look at the <a href="https://aws.amazon.com/serverless/">AWS doc</a> for a better understanding of this post.</p><h4>Design and implementation of the service</h4><p>Considering basic requirements and the characteristics of slash commands, this web app supports the following features.</p><ul><li><strong>Command authentication</strong>. To make the app secure, we must do authentication by at least verifying the token of the slash command. I’d suggest to limit this slash command to be issued only on one dedicated channel by checking the channel_id. Slack also provides other information like user_id for stricter authentication if needed.</li><li><strong>Asynchronous response</strong>. When a slash command sends an HTTP request, it expects the response to be received within 3 seconds. Otherwise, the user invoking the command will see Timeout was reached. Thus, this web app must support asynchronous calls by sending the response to the response_url given in the request body and setting {“response_type&quot;: “in_channel&quot;, “text&quot;: message} to the response body.</li><li><strong>Malformed parameters handling</strong>. Slash commands store the parameters as a string in the text field of the request body. The parameters are separated by a whitespace which will be replaced with + in the request body. For example, the parameters of /command para1 para2 para3 would be transformed to para1+para2+para3 and stored in the value of text. The behavior of using whitespaces as delimiters is often confusing and ignored by users. Thus, the app should handle this case in a user-friendly manner.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*3eCJa4fBL3I84kTmHzfmUQ.png" /><figcaption>Serverless web app provisioned by CDK</figcaption></figure><p>Based on the design and implementation considerations, this web app is realized with the above system architecture where each component is described below.</p><ul><li><strong>API Gateway</strong>.<strong> </strong>The <a href="https://aws.amazon.com/api-gateway/">AWS API Gateway</a> serves as the entrypoint for HTTP requests from our slash command /ecs_deploy &lt;service&gt; &lt;version&gt;. Upon receiving requests, the API Gateway invokes the request validator to do verification.</li><li><strong>Request validator (lambda)</strong>. The request validator, implemented as an <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> function, is responsible for checking whether the token and channel_id are expected as well as the parameters are valid. If so, the request validator sends the request to the request bridge and returns 200 OK to Slack. <strong>By replying to Slack immediately and passing the request event to the request bridge, we can achieve the asynchronousness and address the 3 seconds limit.</strong></li><li><strong>Request bridge (SNS topic)</strong>. The request bridge, implemented as an <a href="https://aws.amazon.com/sns/">AWS SNS</a> topic, acts as a bridge to pass the event message from the request validator to the request handler.</li><li><strong>Request handler (lambda)</strong>. The request handler, also an AWS lambda function, runs the ECS deployment task based on &lt;service&gt;and &lt;version&gt;. When the deployment is completed, the request handler sends the result back to the channel via the response_url. Note that the maximum execution time of a lambda function is 15 minutes that is sufficiently long for the majority of tasks like this one. However, if you’d like apply the architecture in this post for longer tasks, you shall consider to use <a href="https://aws.amazon.com/step-functions/?nc1=h_ls">AWS Step Functions</a>.</li><li><strong>CDK</strong>. To build the entire system, we use <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK</a> which enables developers to define the AWS resources in the programming language and provisions the resources through AWS CloudFormation. With CDK, you can do infrastructure as code more concisely than CloudFormation because CDK does lots of transformations behind the scene.</li></ul><h4>Build the system with AWS CDK</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/172c811c018ec341ee9dca0725d97dd1/href">https://medium.com/media/172c811c018ec341ee9dca0725d97dd1/href</a></iframe><p>To build the serverless system with CDK, we create a CDK Python app named serverless_ecs_deploy. The code snippet above is the procedure of using this CDK app to deploy the system. First, the initialization command cdk init --language python creates the directory structure and associated files. We then write the lambda functions serverless_ecs_deploy/request_validator.py and serverless_ecs_deploy/request_handler.py for the request validator and the request handler, respectively. In serverless_ecs_deploy/serverless_ecs_deploy_stack.py, we declare and associate the objects of the AWS resources in this serverless app. From the code of the serverless_ecs_deploy_stack.py, you can see we can easily use objects to reflect the system architecture with AWS CDK. After we write the three core scripts, we can use cdk synth to review the corresponding CloudFormation template which is actually used to provision the system. Finally, we run cdk deploy to trigger the provisioning of the system defined in serverless_ecs_deploy_stack.py. If everything is fine, the outputs of cdk deploy shows the endpoint of this web app like serverless-ecs-deploy.serverlessecsdeployEndpoint2ADDF30F = <a href="https://ww21uy5vp4.execute-api.us-east-1.amazonaws.com/prod/">https://ww21uy5vp4.execute-api.us-east-1.amazonaws.com/prod/</a>. This is the request url for our slash command /ecs_deploy &lt;service&gt; &lt;version&gt;.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2083dcfc59d1a51c3b955878451b9c0b/href">https://medium.com/media/2083dcfc59d1a51c3b955878451b9c0b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*1Pxrm_xLb0WAiZ_w5o43jQ.png" /><figcaption>serverless_ecs_deploy app structure</figcaption></figure><h4>Summary</h4><p>As more collaboration and communications happen in Slack channels, using Slack slash commands is not only convenient for addressing various tasks but also makes things visible to and traceable for channel members. With AWS serverless, we can realize slash commands at almost no cost. This post intends to demonstrate the benefits and simplicity of combining Slack slash commands and AWS serverless for certain tasks. Welcome to leave your comments if any.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb0d4110f436" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gRPC over TLS with Traefik 2.0 on AWS]]></title>
            <link>https://acmicrox.medium.com/grpc-over-tls-with-traefik-2-0-on-aws-3eed05501b27?source=rss-d9192ff4a153------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eed05501b27</guid>
            <category><![CDATA[traefik]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[grpc-gateway]]></category>
            <dc:creator><![CDATA[Chen-Che Huang]]></dc:creator>
            <pubDate>Mon, 25 Nov 2019 16:13:28 GMT</pubDate>
            <atom:updated>2020-11-11T15:27:20.907Z</atom:updated>
            <content:encoded><![CDATA[<h3>gRPC over TLS with Traefik v2 on AWS</h3><p>In recent years, <a href="https://grpc.io/">gRPC</a> has gained more and more popularity for microservices due to its high performance. Besides inter-service communication, gRPC is very suitable for data communication between mobile apps and backend servers. With highly efficient transmissions of gRPC, mobile apps can fetch data of desired from backend services more quickly. This post introduces how to enable gRPC over TLS for backend services on AWS.</p><h4>gRPC over TLS is not as simple as HTTPS on AWS</h4><p>If you ever set up a HTTPS backend service on AWS, you shall find that it’s pretty simple with AWS load balancers because AWS load balancers inherently support HTTP and SSL termination. Therefore, when you’d like to run a gRPC over TLS backend service on AWS, you probably think that you just need to have an architecture like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*cBTDVdyUgYRENNvXYFX-Cw.png" /></figure><p>Unfortunately, none of the AWS CLB, ALB, and NLB has supported gRPC over TLS yet when this post is written (<strong>Update: </strong><a href="https://aws.amazon.com/blogs/aws/new-application-load-balancer-support-for-end-to-end-http-2-and-grpc/"><strong>AWS ALB has supported gRPC</strong></a><strong> since October 29, 2020</strong>). To overcome this problem, you can let your gRPC server handle SSL termination. However, it’s generally recommended not to offload SSL termination to backend services (see the thread <a href="https://security.stackexchange.com/questions/30403/should-ssl-be-terminated-at-a-load-balancer">https://security.stackexchange.com/questions/30403/should-ssl-be-terminated-at-a-load-balancer</a>).</p><h4>gRPC over TLS with Traefik v2</h4><p>To enable gRPC over TLS and save backend servers from SSL termination, I employ <a href="https://traefik.io/">Traefik</a>, one of the most popular cloud native edge routers, to sit between AWS CLB and gRPC backend servers. The system architecture is shown below. Traefik itself can act as the reverse proxy and load balancers for the backend servers and thus AWS CLB is actually not a must here. The main reason of using AWS CLB is avoid exposing any ec2 instances in the public subnets. If you have no concern for placing Traefik in the public subnets, you don’t need AWS CLB to achieve gRPC over TLS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*a2QZ2c7MqlTHCGUO1RMnxw.png" /></figure><p>In this system architecture, AWS CLB must work in TCP mode to prevent the header fields from being modified. To use gRPC in Traefik, you just need to make Traefik work in HTTP mode and use <em>h2c</em> protocol for communication between Traefik and backend services. For SSL termination, you place the certificate and private key for your domain and let Traefik load them for use. Below are the sample configurations for Traefik with gRPC over TLS. Because this post is not a tutorial for Traefik, please refer to the Traefik doc if it’s difficult for you to understand the sample configuration.</p><p>Traefik static configuration</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb7efd05da3732fba2ff990b34aa54d8/href">https://medium.com/media/cb7efd05da3732fba2ff990b34aa54d8/href</a></iframe><p>Traefik dynamic configuration</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d5ca8853f253d683c3a8a71bf319131/href">https://medium.com/media/7d5ca8853f253d683c3a8a71bf319131/href</a></iframe><h4>Proxy Protocol for Client IPs</h4><p>The system architect and configuration works for gRPC over TLS. However, the backend servers are unable to get the IP addresses of clients because the client IPs in the request headers would be replaced with those of the CLB. To address this issue, you need to enable <em>proxy protocol</em> in your CLB with the commands as well as in Traefik with the updated EntryPoint configuration below. If both are applied, you shall be able to see the client IP in the request header field <em>x-forwarded-for.</em></p><p>CLB commands for proxy protocol</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a35b4ec3abe2ffb79a32f8cfe044725/href">https://medium.com/media/7a35b4ec3abe2ffb79a32f8cfe044725/href</a></iframe><p>Traefik static configuration for proxy protocol</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36a6662a0818e72e2eafb24738a75efb/href">https://medium.com/media/36a6662a0818e72e2eafb24738a75efb/href</a></iframe><h4>Summary</h4><p>This post introduces a feasible system implementation to achieve gRPC over TLS for backend services on AWS. The main advantage of this architecture is that the backend code can be independent of SSL termination. When any of the AWS load balancers starts to support gRPC, nothing needs to be changed in the backend code. If you’d like to verify your implementation, I recommend <a href="https://github.com/uw-labs/bloomrpc">BloomRPC</a> to test efficiently. Welcome to leave your comment if any.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eed05501b27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Consul KV with ACL]]></title>
            <link>https://faun.pub/introduction-to-consul-kv-with-acl-183e4dd7ee1c?source=rss-d9192ff4a153------2</link>
            <guid isPermaLink="false">https://medium.com/p/183e4dd7ee1c</guid>
            <category><![CDATA[consul]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[configuration-management]]></category>
            <dc:creator><![CDATA[Chen-Che Huang]]></dc:creator>
            <pubDate>Wed, 24 Oct 2018 03:51:45 GMT</pubDate>
            <atom:updated>2020-04-05T16:08:32.851Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.consul.io/">Consul</a>, developed by <a href="https://www.hashicorp.com/">HashiCorp</a>, is a service mesh solution with service discovery, configuration, and segmentation functionality. Although Consul is a unified solution for service mesh, each of its functions can be individually used. This article focuses on how to leverage Consul KV to dynamically mange configurations (KV) with ACL. Note that below is based on <strong>Consul 1.4.0-RC1</strong> where the ACL system is rewritten.</p><h4><strong>Run Consul server with ACL</strong></h4><p>A Consul system consists of Consul servers and clients. One or more Consul servers form a cluster to store all the data like KV data and the service catalog. To enable ACL, we first create an ACL configuration acl.json below for Consul servers. We set default_policy deny to block any operation not specifically allowed. The down_policy extend-cache<em> </em>is to apply cached ACLs when the a policy or token cannot be read from the leader of the Consul servers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06a7ac941ae4cfe6ba2bd6d1aeac42ff/href">https://medium.com/media/06a7ac941ae4cfe6ba2bd6d1aeac42ff/href</a></iframe><p>We proceed to start a Consul server with the above ACL configuration by running consul agent -dev -config-file=acl.json. We use -dev to run the server in development mode. Needless to say, -dev should not be used in production! When the server is running, we execute consul acl bootstrap to generate a <strong>master token</strong> which is automatically injected to the server. The master token is the secretID, c66e05fc-61f5–546b-d795-e4e879c15036, as shown below. The master token has unrestricted privileges.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df4ffbd0d97daf4fac78e620f4f042f7/href">https://medium.com/media/df4ffbd0d97daf4fac78e620f4f042f7/href</a></iframe><h4>Create ACL policies and tokens for Consul clients</h4><p>The Consul ACL system is composed of two main components: ACL policies and ACL tokens.</p><ul><li>ACL policies: a policy is a set of rules grouped together in a logical unit that can be reused and linked with many tokens.</li><li>ACL tokens: a token is associated with one ACL policy and is authorized for resource access.</li></ul><p>For configuration management, we shall have two ACL tokens where one can be used to do CRUD operations on keys and the other is for readonly access. Because the permission of a token is determined by the associated policy, we need to create the corresponding policies using the master token as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebce8df2ea182efed163a347aac28294/href">https://medium.com/media/ebce8df2ea182efed163a347aac28294/href</a></iframe><p>With the above policies, we proceed to create the administrative and readonly tokens using the following commands.</p><ul><li>Create administrative token: d112d7de-e018-f933–1118–212762ccde8f</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b81e1c1c75beee49627a034b837e376/href">https://medium.com/media/6b81e1c1c75beee49627a034b837e376/href</a></iframe><ul><li>Create readonly token: c5312125-d375-ba3a-18e4–33c5b3b2f28a</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/259c245c5c002e60223e7f014a3665a6/href">https://medium.com/media/259c245c5c002e60223e7f014a3665a6/href</a></iframe><h4>Use tokens to access Consul KV store</h4><p>With the administrative and readonly tokens, we now can create keys to and read them from the Consul KV store. Because Consul kv cli does not have the -token argument, we use the HTTP requests to interact with the kv store. Consul supports hierarchical KV store and we leverage this to create a session:ttl key under services/api. To be able to create the key, we use the above administrative token d112d7de-e018-f933–1118–212762ccde8f to submit a HTTP PUT request to the Consul server as follows. If nothing goes wrong, you shall see true returned by the Consul server, indicating the request is successful.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b869c6eff68617b204f6bed3d7170f9a/href">https://medium.com/media/b869c6eff68617b204f6bed3d7170f9a/href</a></iframe><p>If you use the readonly token c5312125-d375-ba3a-18e4–33c5b3b2f28a to create the key, you shall see Permission denied returned by the server. However, you shall be allowed to get the value of the key session:ttl with the readonly token like below. Note that the value of each key in Consul KV is encoded by Base64 by default. With the administrative and readonly tokens, you can dynamically manage your configurations with proper access control. For example, you may set the administrative token in your CI/CD process and the configurations can be updated only when the change has been reviewed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bc0536176ed6bc6ce8b5218daf10709/href">https://medium.com/media/1bc0536176ed6bc6ce8b5218daf10709/href</a></iframe><h4>Conclusions</h4><p>This article presents a preliminary introduction to Consul KV with ACL. You can find more advanced features in Consul documents. If you find anything incorrect in this article or have any comments, please let me know. Thanks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*R-ijnctSV2cwo2Q1" /></figure><p><strong>Join our community Slack and read our weekly Faun topics ⬇</strong></p><p><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmedium">Join a Community of Aspiring Developers.Get must-read articles, learn new technologies for free, chat with like-minded people, get job offers, listen to podcasts and more</a></p><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=183e4dd7ee1c" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/introduction-to-consul-kv-with-acl-183e4dd7ee1c">Introduction to Consul KV with ACL</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Superset database migration: from SQLite to MySQL]]></title>
            <link>https://acmicrox.medium.com/superset-database-migration-from-sqlite-to-mysql-c882e5ab9349?source=rss-d9192ff4a153------2</link>
            <guid isPermaLink="false">https://medium.com/p/c882e5ab9349</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[superset]]></category>
            <dc:creator><![CDATA[Chen-Che Huang]]></dc:creator>
            <pubDate>Fri, 21 Sep 2018 08:04:49 GMT</pubDate>
            <atom:updated>2020-04-05T15:36:58.415Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p><a href="https://superset.apache.org/">Superset</a> is a popular data exploration and visualization web application, <a href="https://medium.com/airbnb-engineering/superset-scaling-data-access-and-visual-insights-at-airbnb-3ce3e9b88a7f">originally developed by Airbnb</a> and being an Apache Incubator project now. Superset supports a variety of databases and ships bundled with a SQLite database, <em>superset.db</em>. Because <em>superset.db</em> is connected by Superset by default, it’s common to run the Superset server with <em>superset.db</em> at the beginning. However, as Superset becomes more important, you shall consider to migrate the local SQLite database to a MySQL cluster to to avoid potential data loss. For this data migration, two requirements must be met.</p><ol><li>Superset works with the new MySQL database.</li><li>All data in <em>superset.db</em> are completely dumped to the new MySQL database.</li></ol><h3><strong>Migration procedure</strong></h3><p>Although SQLite and MySQL are two extremely popular database systems, it seems that no free conversion tool is available to directly dump the data from a SQLite database to a MySQL database. Below is a feasible migration procedure of switching from a SQLite database to a MySQL database.</p><h4><strong>Dump the data of <em>superset.db</em> to corresponding SQL statements.</strong></h4><p>SQLite has provided a built-in command dump to make this work easy. With the sqlite3 superset.db .dump &gt; superset_statements.sql, the <em>superset_statements.sql</em> contains all the SQL statements to rebuild <em>superset.db</em>. The <em>superset_statements.sql</em> looks like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d00fa30bfe18275df4787ff795db882/href">https://medium.com/media/2d00fa30bfe18275df4787ff795db882/href</a></iframe><h4><strong>Transform SQLite-compatible statements to MySQL-compatible statements.</strong></h4><p>Due to some syntax difference between SQLite and MySQL, it may not be able to directly use the dumped SQL statements of a SQLite database to create a corresponding MySQL database. In view of this, we need to make the following changes in <em>superset_statements.sql </em>for MySQl-compatibility.</p><ul><li>Change PRAGMA foreign_keys=OFF; to SET FOREIGN_KEY_CHECKS = 0; and BEGIN TRANSACTION; to START RANSACTION;.</li><li>Remove double quotes of the table field in insert statements. For example, change INSERT INTO &quot;user&quot; VALUES (1, &quot;userA&quot;); to INSERT INTO user VALUES (1, &quot;userA&quot;);.</li><li>Run sed -i ‘/\\&quot;/\\\\&quot;/g&#39; superset_sqls.sql for JSON strings with \&quot;.</li><li>Remove table creation statements. Because of the syntax difference in table creation, I choose not to modify the table creation statements. Instead, I create the new MySQL database first (CREATE DATABASE superset CHARACTER SET utf8 COLLATE utf8_bin ) and then use Superset command to create the tables (superset db upgrade &amp;&amp; superset load_examples). If you’re a MySQL newbie like me, remember to specify COLLATE utf8_bin when creating the database for case-sensitive storage.</li></ul><h4><strong>Load the data to the new MySQL database via MySQL-compatible statements</strong></h4><p>With the new database and SQL statements, it is easy to load the data by running mysql -h &lt;mysql_endpoint&gt; -u &lt;username&gt; -p -D superset &lt; superset_statements.sql where mysql is a mysql-client command. When the data has been populated into the new database, you can write a script to verify that each table in MySQL database <em>superset</em> and the corresponding table in <em>superset.db</em> has the same record count. If all go right, modify the configuration file <em>config.py</em> for Superset to make it connect to the new MySQL database and then run the superset server superset runserver -d to do the final confirmation.</p><h4><strong>Summary</strong></h4><p>If you’re experienced with SQLite and MySQL, data migration from SQLite to MySQL shall be easy. If you’re a newbie like me, hope this article is helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c882e5ab9349" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>