SlideShare a Scribd company logo
1 of 33
Download to read offline
Len Chang
08.18 2019
1
▪ Me
▪ The introduction of knex.js
▪ What’s the problem that schema change ?
▪ Create seed data and migration files
▪ How to solve the problem ?
▪ Integrate it with Bitbucket pipeline
▪ Q & A
2
▪ Len Chang
▪ Engineer
▪ Like..
▪ Baseball / Beer / Finance
▪ Coding
▪ JavaScript / Typescript
▪ DB
▪ PostgreSQL / Elasticsearch
▪ Volunteer
▪ Nantou Code Geek
▪ You can find me..
▪ LinkedIn
▪ Facebook
▪ PPT Online
3
Library Docs (Link)
4
▪ Knex.js is a "batteries included" SQL query builder
for Postgres, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon
Redshift designed to be flexible, portable, and fun to use.
▪ Basically it’s the major choice when you use nodejs and RDBMS to do the backend
server.
▪ Features
▪ Query Builder
▪ Pooling
▪ Transactions
▪ Migrations
▪ Seed files
5
▪ Query Builder
▪ The heart of the library, the knex query builder is the interface used for building and
executing standard SQL queries, such as select, insert, update, delete.
▪ Example
knex({ a: 'table', b: 'table' })
.select({
aTitle: 'a.title',
bTitle: 'b.title'
})
.whereRaw('?? = ??', ['a.column_1', 'b.column_2’])
// select "a"."title" as "aTitle", "b"."title" as "bTitle" from "table" as "a", "table" as "b" where "a"."column_1" = "b"."column_2"
6
Application
▪ Pooling
▪ The client created by the configuration initializes a connection pool, using the tarn.js
library. This connection pool has a default setting of a min: 2, max: 10
7
Pooling
Action
Action
Action
PG
Application
Action
Action
Action
PG
▪ Transactions
▪ All queries within a transaction are executed on the same database connection, and run
the entire set of queries as a single unit of work. Any failure will mean the database will
rollback any queries executed on that connection to the pre-transaction state.
▪ Methods
1. As a transaction object
2. As a query builder
8
as a transaction object
▪ Transactions
▪ Methods
1. As a transaction object
2. As a query builder
9
as a transaction object
▪ Migrations
▪ Migrations allow for you to define sets of schema changes so upgrading a database is a
breeze.
10
▪ Seed files
▪ Seed files allow you to populate your database with test or seed data independent of your
migration files.
11
Run seed
12
Testing
1. How to avoid crashing when you
update schema ?
▪ Testing
2. How to avoid operation error ?
▪ Deploy system automatically
13
DB
(version + 1)
Script:
Updating schema
Success (Commit) Failed (Rollback)
DB
(version + 1)
DB
(version)
Dev DB
Script:
Updating schema
QA DB
PROD DB
Dev DB
Dev DB
QA DB
Script:
Updating schemaScript:
Updating schema
3. Doesn’t need to use another tool or code language to do it.
▪ Just JavaScript
14
▪ Summary
▪ How to avoid crashing when you updated schema ?
▪ Testing
▪ How to avoid operation error ?
▪ Deploying system automatically
▪ Doesn’t need to use another tool or code language to do it
▪ Just JavaScript
15
16
▪ Migration
1. knex init => knexfile.ts
17
▪ Migration
2. knex migrate:make migration
▪ Up / Down Functions
18
▪ Migration
3. knex migrate:latest
19
Check migration record
Run
unrecorded
files
▪ Migration Process
20
knexfile.ts
20190814170951_migration.ts
Success (Commit)Failed (Rollback)
Run Migration
▪ Seed data
1. knex init => knexfile.ts
21
▪ Seed data
2. Create seed data
22
▪ Seed data
3. Create seed handling script
and Running
23
▪ Seed Process
24
Seed data of tables
Seed handling Scripts
knex seed:run
DB
Testing, deploying system automatically and just javascript !
25
▪ Testing
▪ Embedded seed testing in migration
Process
26
Transaction
Transaction
▪ Testing
▪ Dividing Environment
▪ All migration script is knex migrate:latest, but
it run different script by different env.
27
▪ deploying system automatically
28
▪ Just javascript
▪ …well…. Just you said that….only javascript.
29
30
31
▪ Advantage
▪ Reduce operation error !
▪ Deploy schema simpler and safer.
▪ Do it by JS developer.
32
LinkedIn
Facebook
PPT Online
33

More Related Content

What's hot

Is It Fast? : Measuring MongoDB Performance
Is It Fast? : Measuring MongoDB PerformanceIs It Fast? : Measuring MongoDB Performance
Is It Fast? : Measuring MongoDB PerformanceTim Callaghan
 
dba_lounge_Iasi: Everybody likes redis
dba_lounge_Iasi: Everybody likes redisdba_lounge_Iasi: Everybody likes redis
dba_lounge_Iasi: Everybody likes redisLiviu Costea
 
When is MyRocks good?
When is MyRocks good? When is MyRocks good?
When is MyRocks good? Alkin Tezuysal
 
InnoDB Scalability improvements in MySQL 8.0
InnoDB Scalability improvements in MySQL 8.0InnoDB Scalability improvements in MySQL 8.0
InnoDB Scalability improvements in MySQL 8.0Mydbops
 
MySQL on AWS RDS
MySQL on AWS RDSMySQL on AWS RDS
MySQL on AWS RDSMydbops
 
WiredTiger Overview
WiredTiger OverviewWiredTiger Overview
WiredTiger OverviewWiredTiger
 
MySQL topology healing at OLA.
MySQL topology healing at OLA.MySQL topology healing at OLA.
MySQL topology healing at OLA.Mydbops
 
What is new in Galera 4 ?
What is new in Galera 4 ?What is new in Galera 4 ?
What is new in Galera 4 ?Mydbops
 
SQL, NoSQL, NewSQL? What's a developer to do?
SQL, NoSQL, NewSQL? What's a developer to do?SQL, NoSQL, NewSQL? What's a developer to do?
SQL, NoSQL, NewSQL? What's a developer to do?Chris Richardson
 
NewSQL overview, Feb 2015
NewSQL overview, Feb 2015NewSQL overview, Feb 2015
NewSQL overview, Feb 2015Ivan Glushkov
 
Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication Mydbops
 
Redis Overview
Redis OverviewRedis Overview
Redis OverviewHoang Long
 
MySQL Performance Schema in Action
MySQL Performance Schema in Action MySQL Performance Schema in Action
MySQL Performance Schema in Action Mydbops
 
Building Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBBuilding Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBAshnikbiz
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & IntroductionJerwin Roy
 
Making MySQL Agile-ish
Making MySQL Agile-ishMaking MySQL Agile-ish
Making MySQL Agile-ishDave Stokes
 

What's hot (20)

Is It Fast? : Measuring MongoDB Performance
Is It Fast? : Measuring MongoDB PerformanceIs It Fast? : Measuring MongoDB Performance
Is It Fast? : Measuring MongoDB Performance
 
dba_lounge_Iasi: Everybody likes redis
dba_lounge_Iasi: Everybody likes redisdba_lounge_Iasi: Everybody likes redis
dba_lounge_Iasi: Everybody likes redis
 
When is MyRocks good?
When is MyRocks good? When is MyRocks good?
When is MyRocks good?
 
InnoDB Scalability improvements in MySQL 8.0
InnoDB Scalability improvements in MySQL 8.0InnoDB Scalability improvements in MySQL 8.0
InnoDB Scalability improvements in MySQL 8.0
 
Couch Db
Couch DbCouch Db
Couch Db
 
MySQL on AWS RDS
MySQL on AWS RDSMySQL on AWS RDS
MySQL on AWS RDS
 
Webpack
WebpackWebpack
Webpack
 
WiredTiger Overview
WiredTiger OverviewWiredTiger Overview
WiredTiger Overview
 
MySQL topology healing at OLA.
MySQL topology healing at OLA.MySQL topology healing at OLA.
MySQL topology healing at OLA.
 
What is new in Galera 4 ?
What is new in Galera 4 ?What is new in Galera 4 ?
What is new in Galera 4 ?
 
Redis
RedisRedis
Redis
 
SQL, NoSQL, NewSQL? What's a developer to do?
SQL, NoSQL, NewSQL? What's a developer to do?SQL, NoSQL, NewSQL? What's a developer to do?
SQL, NoSQL, NewSQL? What's a developer to do?
 
NewSQL overview, Feb 2015
NewSQL overview, Feb 2015NewSQL overview, Feb 2015
NewSQL overview, Feb 2015
 
Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication
 
Redis Overview
Redis OverviewRedis Overview
Redis Overview
 
MySQL Performance Schema in Action
MySQL Performance Schema in Action MySQL Performance Schema in Action
MySQL Performance Schema in Action
 
Building Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBBuilding Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDB
 
Redis IU
Redis IURedis IU
Redis IU
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
Making MySQL Agile-ish
Making MySQL Agile-ishMaking MySQL Agile-ish
Making MySQL Agile-ish
 

Similar to COSCUP 2019 - The discussion between Knex.js and PostgreSQL

The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...
The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...
The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...Databricks
 
001 hbase introduction
001 hbase introduction001 hbase introduction
001 hbase introductionScott Miao
 
MyRocks introduction and production deployment
MyRocks introduction and production deploymentMyRocks introduction and production deployment
MyRocks introduction and production deploymentYoshinori Matsunobu
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadKrivoy Rog IT Community
 
Achieving cyber mission assurance with near real-time impact
Achieving cyber mission assurance with near real-time impactAchieving cyber mission assurance with near real-time impact
Achieving cyber mission assurance with near real-time impactElasticsearch
 
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories. Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories. Andrejs Vorobjovs
 
Serverless Compose vs hurtownia danych
Serverless Compose vs hurtownia danychServerless Compose vs hurtownia danych
Serverless Compose vs hurtownia danychThe Software House
 
Encompassing Information Integration
Encompassing Information IntegrationEncompassing Information Integration
Encompassing Information Integrationnguyenfilip
 
Meetup#2: Building responsive Symbology & Suggest WebService
Meetup#2: Building responsive Symbology & Suggest WebServiceMeetup#2: Building responsive Symbology & Suggest WebService
Meetup#2: Building responsive Symbology & Suggest WebServiceMinsk MongoDB User Group
 
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at DatabricksLessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at DatabricksDatabricks
 
Level 101 for Presto: What is PrestoDB?
Level 101 for Presto: What is PrestoDB?Level 101 for Presto: What is PrestoDB?
Level 101 for Presto: What is PrestoDB?Ali LeClerc
 
Operational foundation for the sql server dba
Operational foundation for the sql server dbaOperational foundation for the sql server dba
Operational foundation for the sql server dbaPeterShore4
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseMarcelo Ochoa
 
19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world
19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world
19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s worldDávid Kőszeghy
 

Similar to COSCUP 2019 - The discussion between Knex.js and PostgreSQL (20)

The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...
The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...
The Modern Data Team for the Modern Data Stack: dbt and the Role of the Analy...
 
Handling scale on AWS
Handling scale on AWSHandling scale on AWS
Handling scale on AWS
 
001 hbase introduction
001 hbase introduction001 hbase introduction
001 hbase introduction
 
MyRocks introduction and production deployment
MyRocks introduction and production deploymentMyRocks introduction and production deployment
MyRocks introduction and production deployment
 
Plantilla oracle
Plantilla oraclePlantilla oracle
Plantilla oracle
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
 
Achieving cyber mission assurance with near real-time impact
Achieving cyber mission assurance with near real-time impactAchieving cyber mission assurance with near real-time impact
Achieving cyber mission assurance with near real-time impact
 
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories. Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
 
Serverless Compose vs hurtownia danych
Serverless Compose vs hurtownia danychServerless Compose vs hurtownia danych
Serverless Compose vs hurtownia danych
 
Encompassing Information Integration
Encompassing Information IntegrationEncompassing Information Integration
Encompassing Information Integration
 
Meetup#2: Building responsive Symbology & Suggest WebService
Meetup#2: Building responsive Symbology & Suggest WebServiceMeetup#2: Building responsive Symbology & Suggest WebService
Meetup#2: Building responsive Symbology & Suggest WebService
 
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at DatabricksLessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
 
Ow
OwOw
Ow
 
Level 101 for Presto: What is PrestoDB?
Level 101 for Presto: What is PrestoDB?Level 101 for Presto: What is PrestoDB?
Level 101 for Presto: What is PrestoDB?
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
Ow
OwOw
Ow
 
Operational foundation for the sql server dba
Operational foundation for the sql server dbaOperational foundation for the sql server dba
Operational foundation for the sql server dba
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the Database
 
19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world
19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world
19. Cloud Native Computing - Kubernetes - Bratislava - Databases in K8s world
 

More from Len Chang

The issue discussion between dml and ddl deployment
The issue discussion between dml and ddl deploymentThe issue discussion between dml and ddl deployment
The issue discussion between dml and ddl deploymentLen Chang
 
DevOps Taiwan meetup #19
DevOps Taiwan meetup #19DevOps Taiwan meetup #19
DevOps Taiwan meetup #19Len Chang
 
2014 Pixnet Hackathonh - EXIF Mining
2014 Pixnet Hackathonh - EXIF Mining2014 Pixnet Hackathonh - EXIF Mining
2014 Pixnet Hackathonh - EXIF MiningLen Chang
 
Hadoop con2016 - Implement Real-time Centralized logging System by Elastic Stack
Hadoop con2016 - Implement Real-time Centralized logging System by Elastic StackHadoop con2016 - Implement Real-time Centralized logging System by Elastic Stack
Hadoop con2016 - Implement Real-time Centralized logging System by Elastic StackLen Chang
 
Agile scrum in startup
Agile scrum in startup  Agile scrum in startup
Agile scrum in startup Len Chang
 
Hadoop Con2015 - The Data Scientist’s Toolbox
Hadoop Con2015 - The Data Scientist’s ToolboxHadoop Con2015 - The Data Scientist’s Toolbox
Hadoop Con2015 - The Data Scientist’s ToolboxLen Chang
 
Spam user detection report
Spam user detection reportSpam user detection report
Spam user detection reportLen Chang
 

More from Len Chang (8)

The issue discussion between dml and ddl deployment
The issue discussion between dml and ddl deploymentThe issue discussion between dml and ddl deployment
The issue discussion between dml and ddl deployment
 
DevOps Taiwan meetup #19
DevOps Taiwan meetup #19DevOps Taiwan meetup #19
DevOps Taiwan meetup #19
 
BI in Xuenn
BI in XuennBI in Xuenn
BI in Xuenn
 
2014 Pixnet Hackathonh - EXIF Mining
2014 Pixnet Hackathonh - EXIF Mining2014 Pixnet Hackathonh - EXIF Mining
2014 Pixnet Hackathonh - EXIF Mining
 
Hadoop con2016 - Implement Real-time Centralized logging System by Elastic Stack
Hadoop con2016 - Implement Real-time Centralized logging System by Elastic StackHadoop con2016 - Implement Real-time Centralized logging System by Elastic Stack
Hadoop con2016 - Implement Real-time Centralized logging System by Elastic Stack
 
Agile scrum in startup
Agile scrum in startup  Agile scrum in startup
Agile scrum in startup
 
Hadoop Con2015 - The Data Scientist’s Toolbox
Hadoop Con2015 - The Data Scientist’s ToolboxHadoop Con2015 - The Data Scientist’s Toolbox
Hadoop Con2015 - The Data Scientist’s Toolbox
 
Spam user detection report
Spam user detection reportSpam user detection report
Spam user detection report
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

COSCUP 2019 - The discussion between Knex.js and PostgreSQL

  • 2. ▪ Me ▪ The introduction of knex.js ▪ What’s the problem that schema change ? ▪ Create seed data and migration files ▪ How to solve the problem ? ▪ Integrate it with Bitbucket pipeline ▪ Q & A 2
  • 3. ▪ Len Chang ▪ Engineer ▪ Like.. ▪ Baseball / Beer / Finance ▪ Coding ▪ JavaScript / Typescript ▪ DB ▪ PostgreSQL / Elasticsearch ▪ Volunteer ▪ Nantou Code Geek ▪ You can find me.. ▪ LinkedIn ▪ Facebook ▪ PPT Online 3
  • 5. ▪ Knex.js is a "batteries included" SQL query builder for Postgres, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use. ▪ Basically it’s the major choice when you use nodejs and RDBMS to do the backend server. ▪ Features ▪ Query Builder ▪ Pooling ▪ Transactions ▪ Migrations ▪ Seed files 5
  • 6. ▪ Query Builder ▪ The heart of the library, the knex query builder is the interface used for building and executing standard SQL queries, such as select, insert, update, delete. ▪ Example knex({ a: 'table', b: 'table' }) .select({ aTitle: 'a.title', bTitle: 'b.title' }) .whereRaw('?? = ??', ['a.column_1', 'b.column_2’]) // select "a"."title" as "aTitle", "b"."title" as "bTitle" from "table" as "a", "table" as "b" where "a"."column_1" = "b"."column_2" 6
  • 7. Application ▪ Pooling ▪ The client created by the configuration initializes a connection pool, using the tarn.js library. This connection pool has a default setting of a min: 2, max: 10 7 Pooling Action Action Action PG Application Action Action Action PG
  • 8. ▪ Transactions ▪ All queries within a transaction are executed on the same database connection, and run the entire set of queries as a single unit of work. Any failure will mean the database will rollback any queries executed on that connection to the pre-transaction state. ▪ Methods 1. As a transaction object 2. As a query builder 8 as a transaction object
  • 9. ▪ Transactions ▪ Methods 1. As a transaction object 2. As a query builder 9 as a transaction object
  • 10. ▪ Migrations ▪ Migrations allow for you to define sets of schema changes so upgrading a database is a breeze. 10
  • 11. ▪ Seed files ▪ Seed files allow you to populate your database with test or seed data independent of your migration files. 11 Run seed
  • 12. 12
  • 13. Testing 1. How to avoid crashing when you update schema ? ▪ Testing 2. How to avoid operation error ? ▪ Deploy system automatically 13 DB (version + 1) Script: Updating schema Success (Commit) Failed (Rollback) DB (version + 1) DB (version) Dev DB Script: Updating schema QA DB PROD DB Dev DB Dev DB QA DB Script: Updating schemaScript: Updating schema
  • 14. 3. Doesn’t need to use another tool or code language to do it. ▪ Just JavaScript 14
  • 15. ▪ Summary ▪ How to avoid crashing when you updated schema ? ▪ Testing ▪ How to avoid operation error ? ▪ Deploying system automatically ▪ Doesn’t need to use another tool or code language to do it ▪ Just JavaScript 15
  • 16. 16
  • 17. ▪ Migration 1. knex init => knexfile.ts 17
  • 18. ▪ Migration 2. knex migrate:make migration ▪ Up / Down Functions 18
  • 19. ▪ Migration 3. knex migrate:latest 19 Check migration record Run unrecorded files
  • 21. ▪ Seed data 1. knex init => knexfile.ts 21
  • 22. ▪ Seed data 2. Create seed data 22
  • 23. ▪ Seed data 3. Create seed handling script and Running 23
  • 24. ▪ Seed Process 24 Seed data of tables Seed handling Scripts knex seed:run DB
  • 25. Testing, deploying system automatically and just javascript ! 25
  • 26. ▪ Testing ▪ Embedded seed testing in migration Process 26 Transaction Transaction
  • 27. ▪ Testing ▪ Dividing Environment ▪ All migration script is knex migrate:latest, but it run different script by different env. 27
  • 28. ▪ deploying system automatically 28
  • 29. ▪ Just javascript ▪ …well…. Just you said that….only javascript. 29
  • 30. 30
  • 31. 31
  • 32. ▪ Advantage ▪ Reduce operation error ! ▪ Deploy schema simpler and safer. ▪ Do it by JS developer. 32