SlideShare a Scribd company logo
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
Schema Migrations
in NOSQL
Dr. Dipali Meher
MCS, M.Phil, NET, Ph.D
Assistant Professor
Modern College of Arts, Science and Commerce,
Ganeshkhind Pune 16
mailtomeher@gmail.com/dipalimeher@moderncollegegk.org
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
2
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
Agenda
 What are database schema?
 Schema changes
 Schema changes in RDBMS
 Schema change sin NOSQL Data
Store
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
⊷ The database schema of a database system is its structure
described in a formal language supported by the database
management system (DBMS).
⊷ The term "schema" refers to the organization of data as a
blueprint of how the database is constructed (divided into
database tables in the case of relational databases).
⊷ The formal definition of a database schema is a set of
formulas (sentences) called integrity constraints imposed
on a database..
⊷ The database schema. This describes how real-world
entities are modeled in the database.
4
Database Schema
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
In NOSQL….
⊷ Recent trends in NOSQL is now schemaless nature – This
allows developers to concentrate on domain design without
worrying about schema changes.
⊷ In case of agility- schema changes are important
⊷ Discussion with domain experts and product owners are
important to understand the data. Discussions should not
contains only the complexity of database schema.
⊷ In case of NOSQL schema changes will be done with least
amount of friction, improving developers productivity and
requires careful attention.
5
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
Schema Changes in RDBMS
⊷ While developing with standard RDBMS technologies, we develop objects, their
corresponding tables, and their relationships.
6
Source: NoSQL Distilled
Prepared By. Dr. Dipali Meher
Schema Changes in a NoSQL Data Store
7
Schema Changes in NOSQL Data Store
Migrations in
Graph
Databases
Changing
Aggregate
Structure
Incremental
Migration
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Schema Changes in NOSQL Data Store
⊷ An RDBMS database has to be changed
before the application is changed. This is
what the schemafree, or schemaless,
approach tries to avoid, aiming at flexibility
of schema changes per entity.
⊷ Frequent changes to the schema are needed
to react to frequent market changes and
product Innovations.
8
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
⊷ When developing with NoSQL databases, in some cases the
schema does not have to be thought about beforehand.
We still have to design and think about other aspects, such as
⊶ Types of relationships (with graph databases),
⊶ Names of the column families, rows, columns,
⊶ Order of columns (with column databases)
⊶ How are the keys assigned and what is the structure of the
data inside the value object (with key-value stores).
9
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
⊷ It is seen that it is applications responsibility to take care of
database schema and data is accepted through application
which is to be saved at database.( e.g. verification and
validation by an application while accepting data)
⊷ When data is not parsed to database by application then
database may throw an error which is to be encountered by an
application. So while designing schemaless databases,
applications and data which is to be stored both are taking
into consideration.
⊷ Schema changes especially matter when there is a deployed
application and existing production data.
10
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Example of Mongodb
⊷ Consider data model as customer, order, orderItems as follows..
{ "_id": "
4BD8AE97C47016442AF4A580",
"customerid": 99999,
"name": "Foo Sushi Inc",
"since": "12/12/2012",
"order": {
"orderid": "4821-UXWE-122012","orderdate": "12/12/2001",
"orderItems": [{"product": "Fortune Cookies",
"price": 19.99}]
}
}
11
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Application code to write this document
structure to MongoDB:
BasicDBObject orderItem = new
BasicDBObject();
orderItem.put("product", productName);
orderItem.put("price", price);
orderItems.add(orderItem);
12
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Code to read the document back from the database:
BasicDBObject item = (BasicDBObject)
orderItem;
String productName =
item.getString("product");
Double price = item.getDouble("price");
13
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
⊷ Changing the objects to add preferredShippingType does not require
any change in the database, as the database does not care that
different documents do not follow the same schema.
⊷ This allows for faster development and easy deployments. All that
needs to be deployed is the application—no changes on the database
side are needed.
⊷ The code has to make sure that documents that do not have the
preferredShippingType attribute can still be parsed
14
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Example of schema changes
⊷ introducing discountedPrice and renaming price to
fullPrice. To make this change,
⊷ we rename the price attribute to fullPrice and add
discountedPrice attribute.
⊷ The changed document is
15
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
{ "_id": "
5BD8AE97C47016442AF4A580",
"customerid": 66778,
"name": "India House",
"since": "12/12/2012",
"order": {
"orderid": "4821-UXWE-222012",
"orderdate": "12/12/2001",
"orderItems": [{"product": "Chair Covers",
"fullPrice": 29.99,
"discountedPrice":26.99}]
}
}
16
Once we deploy this change, new customers and their orders can be saved and read back without
problems, but for existing orders the price of their product cannot be read, because now the code is
looking for fullPrice but the document has only price.
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Incremental Migration
⊷ Schema mismatch gives new conversion to NOSQL world.
⊷ When schema is changed on the application, we have to make sure to
convert all the existing data to the new schema (depending on data size,
this might be an expensive operation).
⊷ Another option would be to make sure that data, before the schema
changed, can still be parsed by the new code, and when it’s saved, it is
saved back in the new schema.
⊷ This technique, known as incremental migration, will migrate data over
time;
⊷ some data may never get migrated, because it was never accessed.
17
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Incremental Migration
The incremental migration technique can also be
implemented with a schema_version field on
the data, used by the application to choose the
correct code to parse the data into the objects.
When saving, the data is migrated to the latest
version and the schema_version is updated to
reflect that.
18
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Incremental Migration
⊷ A proper translation layer between your domain and
the database is important so that, as the schema
changes, managing multiple versions of the schema is
restricted to the translation layer and does not leak into
the whole application.
⊷ Mobile apps create special requirements. Since we
cannot enforce the latest upgrades of the application,
the application should be able to handle almost all
versions of the schema.
19
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Example Incremental Migration
Read price and fullPrice from document
BasicDBObject item = (BasicDBObject) orderItem;
String productName = item.getString("product");
Double fullPrice = item.getDouble("price");
if (fullPrice == null) {
fullPrice = item.getDouble("fullPrice");
}
Double discountedPrice =
item.getDouble("discountedPrice");
20
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
When writing the document back, the old attribute
price is not saved:
BasicDBObject orderItem = new
BasicDBObject();
orderItem.put("product", productName);
orderItem.put("fullPrice", price);
orderItem.put("discountedPrice",
discountedPrice);
orderItems.add(orderItem);
21
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
When using incremental migration, there
could be many versions of the object on
the application side that can translate the
old schema to the new schema; while
saving the object back, it is saved using
the new object. This gradual migration
of the data helps the application evolve
faster.
22
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
The incremental migration technique will
complicate the object design, especially as
new changes are being introduced yet old
changes are not being taken out.
This period between the change deployment
and the last object in the database migrating
to the new schema is known as the transition
period
23
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Transition Period of Schema Changes
24
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Migrations in Graph Databases
⊷ Graph databases have edges that have types and properties.
If you change the type of these edges in the codebase, you
no longer can traverse the database, rendering it unusable.
⊷ To get around this, you can traverse all the edges and change
the type of each edge.
⊷ This operation can be expensive and requires you to write
code to migrate all the edges in the database.
25
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Migrations in Graph Databases
⊷ If we need to maintain backward compatibility or do not
want to change the whole graph in one go, we can just
create new edges between the nodes; later when we are
comfortable about the change, the old edges can be
dropped.
⊷ We can use traversals with multiple edge types to traverse
the graph using the new and old edge types.
⊷ This technique may help a great deal with large databases,
especially if we want to maintain high availability.
26
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Migrations in Graph Databases
⊷ If we have to change properties on all the nodes or edges, we
have to fetch all the nodes and change all the properties that
need to be changed.
⊷ An example would be adding NodeCreatedBy and
NodeCreatedOn to all existing nodes to track the changes
being made to each node.
27
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Migrations in Graph Databases
for (Node node : database.getAllNodes())
{
node.setProperty("NodeCreatedBy", getSystemUser());
node.setProperty("NodeCreatedOn",
getSystemTimeStamp());
}
⊷ We may have to change the data in the nodes. New data
may be derived from the existing node data, or it could
be imported from some other source.
⊷ The migration can be done by fetching all nodes using
an index provided by the source of data and writing
relevant data to each node.
28
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Changing Aggregate Structure
⊷ Sometimes you need to change the schema design.
⊷ Example by splitting large objects into smaller ones that are stored
independently.
⊷ Suppose you have a customer aggregate that contains all the customers orders,
and you want to separate the customer and each of their orders into different
aggregate units.
⊷ You then have to ensure that the code can work with both versions of the
aggregates. If it does not find the old objects, it will look for the new
aggregates.
⊷ Code that runs in the background can read one aggregate at a time, make the
necessary change, and save the data back into different aggregates.
⊷ The advantage of operating on one aggregate at a time is that this way, you’re
not affecting data availability for the application.
29
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
30
Source: NoSQL Distilled
Prepared by Dr. Dipali Meher
Questions to be asked
⊷ Write a short note on Graph Databases.
⊷ What is transition period?
⊷ What is incremental migration?
⊷ Explain incremental migration with and example.
⊷ Write a short note on incremental migration.
⊷ How schema changes will take place in NOSQL data
store? Explain with an example.
⊷ How Schema changes will be done in RDBMS?
Explain with an example.
31

More Related Content

What's hot

No sql distilled-distilled
No sql distilled-distilledNo sql distilled-distilled
No sql distilled-distilledrICh morrow
 
NoSql
NoSqlNoSql
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
Harri Kauhanen
 
5 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/25 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/2
Fabio Fumarola
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and Uses
Suvradeep Rudra
 
NoSQL databases - An introduction
NoSQL databases - An introductionNoSQL databases - An introduction
NoSQL databases - An introduction
Pooyan Mehrparvar
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
Mohammed Fazuluddin
 
Chapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choicesChapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choices
Maynooth University
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnit
Eric Wendelin
 
Nosql-Module 1 PPT.pptx
Nosql-Module 1 PPT.pptxNosql-Module 1 PPT.pptx
Nosql-Module 1 PPT.pptx
Radhika R
 
Introduction to Apache Cassandra
Introduction to Apache Cassandra Introduction to Apache Cassandra
Introduction to Apache Cassandra
Knoldus Inc.
 
SQL vs MongoDB
SQL vs MongoDBSQL vs MongoDB
SQL vs MongoDB
calltutors
 
Schemaless Databases
Schemaless DatabasesSchemaless Databases
Schemaless Databases
Dan Gunter
 
SQL/NoSQL How to choose ?
SQL/NoSQL How to choose ?SQL/NoSQL How to choose ?
SQL/NoSQL How to choose ?
Venu Anuganti
 
Chapter 4 terminolgy of keyvalue databses from nosql for mere mortals
Chapter 4 terminolgy of keyvalue databses from nosql for mere mortalsChapter 4 terminolgy of keyvalue databses from nosql for mere mortals
Chapter 4 terminolgy of keyvalue databses from nosql for mere mortals
nehabsairam
 
Sql vs NoSQL-Presentation
 Sql vs NoSQL-Presentation Sql vs NoSQL-Presentation
Sql vs NoSQL-Presentation
Shubham Tomar
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
Habilelabs
 
Hadoop introduction , Why and What is Hadoop ?
Hadoop introduction , Why and What is  Hadoop ?Hadoop introduction , Why and What is  Hadoop ?
Hadoop introduction , Why and What is Hadoop ?
sudhakara st
 
Introduction to NOSQL databases
Introduction to NOSQL databasesIntroduction to NOSQL databases
Introduction to NOSQL databases
Ashwani Kumar
 

What's hot (20)

No sql distilled-distilled
No sql distilled-distilledNo sql distilled-distilled
No sql distilled-distilled
 
NoSql
NoSqlNoSql
NoSql
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
5 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/25 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/2
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and Uses
 
NoSQL databases - An introduction
NoSQL databases - An introductionNoSQL databases - An introduction
NoSQL databases - An introduction
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
 
Chapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choicesChapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choices
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnit
 
Nosql-Module 1 PPT.pptx
Nosql-Module 1 PPT.pptxNosql-Module 1 PPT.pptx
Nosql-Module 1 PPT.pptx
 
Introduction to Apache Cassandra
Introduction to Apache Cassandra Introduction to Apache Cassandra
Introduction to Apache Cassandra
 
SQL vs MongoDB
SQL vs MongoDBSQL vs MongoDB
SQL vs MongoDB
 
Schemaless Databases
Schemaless DatabasesSchemaless Databases
Schemaless Databases
 
SQL/NoSQL How to choose ?
SQL/NoSQL How to choose ?SQL/NoSQL How to choose ?
SQL/NoSQL How to choose ?
 
Chapter 4 terminolgy of keyvalue databses from nosql for mere mortals
Chapter 4 terminolgy of keyvalue databses from nosql for mere mortalsChapter 4 terminolgy of keyvalue databses from nosql for mere mortals
Chapter 4 terminolgy of keyvalue databses from nosql for mere mortals
 
Sql vs NoSQL-Presentation
 Sql vs NoSQL-Presentation Sql vs NoSQL-Presentation
Sql vs NoSQL-Presentation
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Hadoop introduction , Why and What is Hadoop ?
Hadoop introduction , Why and What is  Hadoop ?Hadoop introduction , Why and What is  Hadoop ?
Hadoop introduction , Why and What is Hadoop ?
 
Introduction to NOSQL databases
Introduction to NOSQL databasesIntroduction to NOSQL databases
Introduction to NOSQL databases
 

Similar to Schema migrations in no sql

CS828 P5 Individual Project v101
CS828 P5 Individual Project v101CS828 P5 Individual Project v101
CS828 P5 Individual Project v101ThienSi Le
 
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
KrishnaShah908060
 
NoSQL Basics and MongDB
NoSQL Basics and  MongDBNoSQL Basics and  MongDB
NoSQL Basics and MongDB
Shamima Yeasmin Mukta
 
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
Vivek Adithya Mohankumar
 
Know what is NOSQL
Know what is NOSQL Know what is NOSQL
Know what is NOSQL
Prasoon Sharma
 
C1803041317
C1803041317C1803041317
C1803041317
IOSR Journals
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
Praveen M Jigajinni
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
balwinders
 
MongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data scienceMongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data science
bitragowthamkumar1
 
A Seminar on NoSQL Databases.
A Seminar on NoSQL Databases.A Seminar on NoSQL Databases.
A Seminar on NoSQL Databases.
Navdeep Charan
 
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMINGEVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
ijiert bestjournal
 
2.Introduction to NOSQL (Core concepts).pptx
2.Introduction to NOSQL (Core concepts).pptx2.Introduction to NOSQL (Core concepts).pptx
2.Introduction to NOSQL (Core concepts).pptx
RushikeshChikane2
 
Erciyes university
Erciyes universityErciyes university
Erciyes university
hothaifa alkhazraji
 
Unit-10.pptx
Unit-10.pptxUnit-10.pptx
Unit-10.pptx
GhanashyamBK1
 
NoSQL Databases Introduction - UTN 2013
NoSQL Databases Introduction - UTN 2013NoSQL Databases Introduction - UTN 2013
NoSQL Databases Introduction - UTN 2013
Facundo Farias
 
Nosql
NosqlNosql
Nosql
ROXTAD71
 

Similar to Schema migrations in no sql (20)

CS828 P5 Individual Project v101
CS828 P5 Individual Project v101CS828 P5 Individual Project v101
CS828 P5 Individual Project v101
 
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
 
NoSQL Basics and MongDB
NoSQL Basics and  MongDBNoSQL Basics and  MongDB
NoSQL Basics and MongDB
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
 
Know what is NOSQL
Know what is NOSQL Know what is NOSQL
Know what is NOSQL
 
No sql database
No sql databaseNo sql database
No sql database
 
NoSQL
NoSQLNoSQL
NoSQL
 
C1803041317
C1803041317C1803041317
C1803041317
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
MongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data scienceMongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data science
 
A Seminar on NoSQL Databases.
A Seminar on NoSQL Databases.A Seminar on NoSQL Databases.
A Seminar on NoSQL Databases.
 
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMINGEVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
 
2.Introduction to NOSQL (Core concepts).pptx
2.Introduction to NOSQL (Core concepts).pptx2.Introduction to NOSQL (Core concepts).pptx
2.Introduction to NOSQL (Core concepts).pptx
 
Nosql
NosqlNosql
Nosql
 
Erciyes university
Erciyes universityErciyes university
Erciyes university
 
Unit-10.pptx
Unit-10.pptxUnit-10.pptx
Unit-10.pptx
 
NoSQL Databases Introduction - UTN 2013
NoSQL Databases Introduction - UTN 2013NoSQL Databases Introduction - UTN 2013
NoSQL Databases Introduction - UTN 2013
 
Nosql
NosqlNosql
Nosql
 

More from Dr-Dipali Meher

Database Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,ViewDatabase Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,View
Dr-Dipali Meher
 
DataPreprocessing.pptx
DataPreprocessing.pptxDataPreprocessing.pptx
DataPreprocessing.pptx
Dr-Dipali Meher
 
Literature Review
Literature ReviewLiterature Review
Literature Review
Dr-Dipali Meher
 
Research Problem
Research ProblemResearch Problem
Research Problem
Dr-Dipali Meher
 
Formulation of Research Design
Formulation of Research DesignFormulation of Research Design
Formulation of Research Design
Dr-Dipali Meher
 
Types of Research
Types of ResearchTypes of Research
Types of Research
Dr-Dipali Meher
 
Research Methodology-Intorduction
Research Methodology-IntorductionResearch Methodology-Intorduction
Research Methodology-Intorduction
Dr-Dipali Meher
 
Introduction to Research
Introduction to ResearchIntroduction to Research
Introduction to Research
Dr-Dipali Meher
 
Naive bayesian classification
Naive bayesian classificationNaive bayesian classification
Naive bayesian classification
Dr-Dipali Meher
 
Data mining an introduction
Data mining an introductionData mining an introduction
Data mining an introduction
Dr-Dipali Meher
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 

More from Dr-Dipali Meher (11)

Database Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,ViewDatabase Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,View
 
DataPreprocessing.pptx
DataPreprocessing.pptxDataPreprocessing.pptx
DataPreprocessing.pptx
 
Literature Review
Literature ReviewLiterature Review
Literature Review
 
Research Problem
Research ProblemResearch Problem
Research Problem
 
Formulation of Research Design
Formulation of Research DesignFormulation of Research Design
Formulation of Research Design
 
Types of Research
Types of ResearchTypes of Research
Types of Research
 
Research Methodology-Intorduction
Research Methodology-IntorductionResearch Methodology-Intorduction
Research Methodology-Intorduction
 
Introduction to Research
Introduction to ResearchIntroduction to Research
Introduction to Research
 
Naive bayesian classification
Naive bayesian classificationNaive bayesian classification
Naive bayesian classification
 
Data mining an introduction
Data mining an introductionData mining an introduction
Data mining an introduction
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 

Recently uploaded

Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Landownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptxLandownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptx
JezreelCabil2
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
AG2 Design
 

Recently uploaded (20)

Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Landownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptxLandownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
 

Schema migrations in no sql

  • 1. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher Schema Migrations in NOSQL Dr. Dipali Meher MCS, M.Phil, NET, Ph.D Assistant Professor Modern College of Arts, Science and Commerce, Ganeshkhind Pune 16 mailtomeher@gmail.com/dipalimeher@moderncollegegk.org
  • 2. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher 2
  • 3. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher Agenda  What are database schema?  Schema changes  Schema changes in RDBMS  Schema change sin NOSQL Data Store
  • 4. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher ⊷ The database schema of a database system is its structure described in a formal language supported by the database management system (DBMS). ⊷ The term "schema" refers to the organization of data as a blueprint of how the database is constructed (divided into database tables in the case of relational databases). ⊷ The formal definition of a database schema is a set of formulas (sentences) called integrity constraints imposed on a database.. ⊷ The database schema. This describes how real-world entities are modeled in the database. 4 Database Schema
  • 5. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher In NOSQL…. ⊷ Recent trends in NOSQL is now schemaless nature – This allows developers to concentrate on domain design without worrying about schema changes. ⊷ In case of agility- schema changes are important ⊷ Discussion with domain experts and product owners are important to understand the data. Discussions should not contains only the complexity of database schema. ⊷ In case of NOSQL schema changes will be done with least amount of friction, improving developers productivity and requires careful attention. 5
  • 6. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher Schema Changes in RDBMS ⊷ While developing with standard RDBMS technologies, we develop objects, their corresponding tables, and their relationships. 6
  • 7. Source: NoSQL Distilled Prepared By. Dr. Dipali Meher Schema Changes in a NoSQL Data Store 7 Schema Changes in NOSQL Data Store Migrations in Graph Databases Changing Aggregate Structure Incremental Migration
  • 8. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Schema Changes in NOSQL Data Store ⊷ An RDBMS database has to be changed before the application is changed. This is what the schemafree, or schemaless, approach tries to avoid, aiming at flexibility of schema changes per entity. ⊷ Frequent changes to the schema are needed to react to frequent market changes and product Innovations. 8
  • 9. Source: NoSQL Distilled Prepared by Dr. Dipali Meher ⊷ When developing with NoSQL databases, in some cases the schema does not have to be thought about beforehand. We still have to design and think about other aspects, such as ⊶ Types of relationships (with graph databases), ⊶ Names of the column families, rows, columns, ⊶ Order of columns (with column databases) ⊶ How are the keys assigned and what is the structure of the data inside the value object (with key-value stores). 9
  • 10. Source: NoSQL Distilled Prepared by Dr. Dipali Meher ⊷ It is seen that it is applications responsibility to take care of database schema and data is accepted through application which is to be saved at database.( e.g. verification and validation by an application while accepting data) ⊷ When data is not parsed to database by application then database may throw an error which is to be encountered by an application. So while designing schemaless databases, applications and data which is to be stored both are taking into consideration. ⊷ Schema changes especially matter when there is a deployed application and existing production data. 10
  • 11. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Example of Mongodb ⊷ Consider data model as customer, order, orderItems as follows.. { "_id": " 4BD8AE97C47016442AF4A580", "customerid": 99999, "name": "Foo Sushi Inc", "since": "12/12/2012", "order": { "orderid": "4821-UXWE-122012","orderdate": "12/12/2001", "orderItems": [{"product": "Fortune Cookies", "price": 19.99}] } } 11
  • 12. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Application code to write this document structure to MongoDB: BasicDBObject orderItem = new BasicDBObject(); orderItem.put("product", productName); orderItem.put("price", price); orderItems.add(orderItem); 12
  • 13. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Code to read the document back from the database: BasicDBObject item = (BasicDBObject) orderItem; String productName = item.getString("product"); Double price = item.getDouble("price"); 13
  • 14. Source: NoSQL Distilled Prepared by Dr. Dipali Meher ⊷ Changing the objects to add preferredShippingType does not require any change in the database, as the database does not care that different documents do not follow the same schema. ⊷ This allows for faster development and easy deployments. All that needs to be deployed is the application—no changes on the database side are needed. ⊷ The code has to make sure that documents that do not have the preferredShippingType attribute can still be parsed 14
  • 15. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Example of schema changes ⊷ introducing discountedPrice and renaming price to fullPrice. To make this change, ⊷ we rename the price attribute to fullPrice and add discountedPrice attribute. ⊷ The changed document is 15
  • 16. Source: NoSQL Distilled Prepared by Dr. Dipali Meher { "_id": " 5BD8AE97C47016442AF4A580", "customerid": 66778, "name": "India House", "since": "12/12/2012", "order": { "orderid": "4821-UXWE-222012", "orderdate": "12/12/2001", "orderItems": [{"product": "Chair Covers", "fullPrice": 29.99, "discountedPrice":26.99}] } } 16 Once we deploy this change, new customers and their orders can be saved and read back without problems, but for existing orders the price of their product cannot be read, because now the code is looking for fullPrice but the document has only price.
  • 17. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Incremental Migration ⊷ Schema mismatch gives new conversion to NOSQL world. ⊷ When schema is changed on the application, we have to make sure to convert all the existing data to the new schema (depending on data size, this might be an expensive operation). ⊷ Another option would be to make sure that data, before the schema changed, can still be parsed by the new code, and when it’s saved, it is saved back in the new schema. ⊷ This technique, known as incremental migration, will migrate data over time; ⊷ some data may never get migrated, because it was never accessed. 17
  • 18. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Incremental Migration The incremental migration technique can also be implemented with a schema_version field on the data, used by the application to choose the correct code to parse the data into the objects. When saving, the data is migrated to the latest version and the schema_version is updated to reflect that. 18
  • 19. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Incremental Migration ⊷ A proper translation layer between your domain and the database is important so that, as the schema changes, managing multiple versions of the schema is restricted to the translation layer and does not leak into the whole application. ⊷ Mobile apps create special requirements. Since we cannot enforce the latest upgrades of the application, the application should be able to handle almost all versions of the schema. 19
  • 20. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Example Incremental Migration Read price and fullPrice from document BasicDBObject item = (BasicDBObject) orderItem; String productName = item.getString("product"); Double fullPrice = item.getDouble("price"); if (fullPrice == null) { fullPrice = item.getDouble("fullPrice"); } Double discountedPrice = item.getDouble("discountedPrice"); 20
  • 21. Source: NoSQL Distilled Prepared by Dr. Dipali Meher When writing the document back, the old attribute price is not saved: BasicDBObject orderItem = new BasicDBObject(); orderItem.put("product", productName); orderItem.put("fullPrice", price); orderItem.put("discountedPrice", discountedPrice); orderItems.add(orderItem); 21
  • 22. Source: NoSQL Distilled Prepared by Dr. Dipali Meher When using incremental migration, there could be many versions of the object on the application side that can translate the old schema to the new schema; while saving the object back, it is saved using the new object. This gradual migration of the data helps the application evolve faster. 22
  • 23. Source: NoSQL Distilled Prepared by Dr. Dipali Meher The incremental migration technique will complicate the object design, especially as new changes are being introduced yet old changes are not being taken out. This period between the change deployment and the last object in the database migrating to the new schema is known as the transition period 23
  • 24. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Transition Period of Schema Changes 24
  • 25. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Migrations in Graph Databases ⊷ Graph databases have edges that have types and properties. If you change the type of these edges in the codebase, you no longer can traverse the database, rendering it unusable. ⊷ To get around this, you can traverse all the edges and change the type of each edge. ⊷ This operation can be expensive and requires you to write code to migrate all the edges in the database. 25
  • 26. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Migrations in Graph Databases ⊷ If we need to maintain backward compatibility or do not want to change the whole graph in one go, we can just create new edges between the nodes; later when we are comfortable about the change, the old edges can be dropped. ⊷ We can use traversals with multiple edge types to traverse the graph using the new and old edge types. ⊷ This technique may help a great deal with large databases, especially if we want to maintain high availability. 26
  • 27. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Migrations in Graph Databases ⊷ If we have to change properties on all the nodes or edges, we have to fetch all the nodes and change all the properties that need to be changed. ⊷ An example would be adding NodeCreatedBy and NodeCreatedOn to all existing nodes to track the changes being made to each node. 27
  • 28. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Migrations in Graph Databases for (Node node : database.getAllNodes()) { node.setProperty("NodeCreatedBy", getSystemUser()); node.setProperty("NodeCreatedOn", getSystemTimeStamp()); } ⊷ We may have to change the data in the nodes. New data may be derived from the existing node data, or it could be imported from some other source. ⊷ The migration can be done by fetching all nodes using an index provided by the source of data and writing relevant data to each node. 28
  • 29. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Changing Aggregate Structure ⊷ Sometimes you need to change the schema design. ⊷ Example by splitting large objects into smaller ones that are stored independently. ⊷ Suppose you have a customer aggregate that contains all the customers orders, and you want to separate the customer and each of their orders into different aggregate units. ⊷ You then have to ensure that the code can work with both versions of the aggregates. If it does not find the old objects, it will look for the new aggregates. ⊷ Code that runs in the background can read one aggregate at a time, make the necessary change, and save the data back into different aggregates. ⊷ The advantage of operating on one aggregate at a time is that this way, you’re not affecting data availability for the application. 29
  • 30. Source: NoSQL Distilled Prepared by Dr. Dipali Meher 30
  • 31. Source: NoSQL Distilled Prepared by Dr. Dipali Meher Questions to be asked ⊷ Write a short note on Graph Databases. ⊷ What is transition period? ⊷ What is incremental migration? ⊷ Explain incremental migration with and example. ⊷ Write a short note on incremental migration. ⊷ How schema changes will take place in NOSQL data store? Explain with an example. ⊷ How Schema changes will be done in RDBMS? Explain with an example. 31