📺 Develpreneur YouTube Episode

Video + transcript

SQL Sync Lessons Learned Part 3

2022-12-27 •Youtube

Detailed Notes

After our series of building a python application to synchronize databases at the schema and data level we have lessons learned. There are areas where we need to be intentional as we decide how to maintain and enhance our databases. This is the final part.

Learn More at https://develpreneur.com

Transcript Text
thank you
[Music]
and it becomes which is why it became a
really fun combo project because while
there's a lot of little pythony things
that we ran into
uh really a lot of it is a is an
exploration of what
my sequel in particular
um stores and where it stores it about
the database itself and it it's
different if you're in Oracle or uh SQL
server or db2 but generally speaking the
problem the uh
the properties and details do exist
within the database itself so you can
query it almost in a reflection kind of
mode create about it so that you can
actually pull that and with some thought
you generate SQL and then execute that
SQL against your uh
whatever your target or your your
destination is and what you end up
getting is something where you know
probably what you're what you want to do
and what you want to think through if
you're going to synchronize your
databases how
how detailed do I want it to be is it
good enough for me to have just the
tables the tables the table structures
and the stored procedures and if the
tables are basically all empty of data
is that okay in some cases it is because
you can you can go in and maybe follow
it up with some little like quick uh
test script or something like that
particularly if you have automated
testing and regression testing then it
may be something where you say hey all I
need to do is just have an empty
database
that I'm going to create and then I'm
going to run this test script and it's
going to put some data in there for me
and I can maybe even script a couple of
bonus things there
and that becomes extremely useful
if you run in a situation where which
I've been to a couple of those where
you're at a job you're on a project and
you say hey I want to be able to like
see the I want to be able to create from
scratch the database and somebody says
oh that doesn't exist we don't have that
SQL
now you can in some cases you can do a
database dump
and get that SQL where you can do it
without the data
um but sometimes it's something like
this would be a little bit better you
know approach where you can bring it in
clean into your development environment
make some tweaks if you need to and then
you know export it or Point your
documentation tool towards it
so
that was sort of a you know there's a
lot of high level stuff there but the
you know with the key being to sort of
highlight
some of the things to think about if you
want to synchronize or if you're putting
together processes for promoting
databases through your your system
and so that being said questions
comments
so have you actually looked at something
called liquid base which might
kind of simplify that I don't know if
it's just Java based only but we use
Liquid based in that allows you to
basically build the
data or I guess the table structures in
that in the code so every time you
deploy it deploys the SQL
yeah there's I mean there are tools out
there that
do stuff like this
um
and it really is it's a
if you're doing it right from the start
you can like because liquid base is a
great tool for that and you can also do
reverse engineering uh like we mentioned
right Django is one if you're using some
of the tools out there like I think even
hibernate was one that had
um ways to generate a database I know
there's other you know object relational
mappers like that where
it may if you do it right from the start
then it shouldn't be an issue you should
have scripts and changes and you know
migration steps and things like that
that allow you to
maintain your database but this is also
dealing with data and things like that
that look like a liquid base is really a
structural it's much more structural
thing
and not a way to potentially copy data
so you know it's this is really like
taking well you can use the first bits
of this and use it strictly for
structural content the challenge becomes
when you want to do more than this when
you want to actually have data to move
from one place to another it's like how
do I how do I do that it's not like
copying a file from you know one system
to another because now you're like
grabbing just bits and pieces and not
the whole thing or at least you know if
you do the whole thing it's it's like
dump and restore if you want to do
pieces of it it gets a little more
complicated
yeah that makes sense yeah good point
though I mean because like there are
some really cool tools out there for
that piece of it
other questions and comments
only other thing is uh have you also
thought about moving your SQL out into
like a properties file and load it in
that way
uh I'm not sure I understand what do you
do so like within your python code you
had all the different selects inputs and
all that if you uh put that into like a
properties file you could inject your
SQL
uh wherever you wanted kind of like a
store procedure and then just uh update
tokens or update uh you know the inject
the data you need
uh that's sort of what it
that's sort of what it is if you um
did it come up okay so like for example
here these are
you could this this could easily be
that's that would be a way to do it
because right now and it's to get into a
little bit is it like this is the MySQL
synchronized script so it has uh my SQL
specific stuff
the thought being that if I had a Oracle
then it would be the same stuff but it
would be uh you know oracle synchronized
and then I'd do the Oracle specific code
within this now I could within here say
each of these and say hey this is going
to be a
um you know I could extract that out and
say hey this is you know property X for
my SQL and I could just swap out my
settings files
it's you could do that but it seems like
it's an extra level that doesn't uh that
wouldn't make I don't know I'm gonna say
I was gonna say it wouldn't make it as
readable
um because it's nice to be able to see
right here it's like oh here's what it's
doing you know this is where I'm getting
the data this isn't data I'm pulling
from it
um
and I'm not reusing these too terribly
often
um so it's
yeah it could be extracted out I'm not
sure that that's I'm not sure if I if I
see enough of a benefit for it other
than if you want to do it a little
differently as far as how you
um are able to abstract and set stuff up
I mean in this case I'm it's done
through like hey I've got I'll have the
thought is I would have different
classes for different databases versus
just different setting files for
different databases which would be
possible for itself as well
right no I was just looking at your
Source destination it's like you're
duplicating the SQL so why not just put
all the SQL in one class and that like
here here's all your
here's all the SQL
in one place and you just go read it
there and then you apply it wherever you
need to apply it that's true and that
may be
um
you know that maybe in particular
because it's like
it's usually in the same place but you
do see there are like duplicates here so
it's like the you know the really the
difference between these two are just
the name
um so it could be something like just
you know slap that in there and then
give it a different uh like create that
as a template and then slap the names in
um and maybe it could be reused in
places and that may be something that's
part of the cleanup that ends up coming
as we get further into it is it maybe
like hey let's go ahead and take some of
these things where we see repeated SQL
and clean that up and make that you know
give that a Slicker little interface so
good point yeah the reason I mentioned
that is because you said like that's for
my sequel well if you want to go to
Oracle some of those queries might
change but you could essentially take
the same queries just tweak them for
Oracle and then just apply it to a
different utility
yeah and that may be something too where
it's one of those where it's useful sort
of like a um a resource bundle kind of
approach is that even though it's
different classes and then if you take
the
um if you take those seek those SQL
things and say hey these These are the
quick and take all those and Abstract
them up to you know like up on the class
level and hear you know where you'd have
like you know uh uh so you'd have like
well like SQL one SQL two whatever it is
whatever you call those and so then if
you're when you
create the Oracle synchronized class
then you just you see right there here's
where all my SQL is so I can just go
right here and go through my say the SQL
and change it over to use Oracle stuff
but the thought also is that Oracle or
SQL Server is going to be different
enough that you're probably going to
have to change several of the things
that are done in particular here because
you're going through and you're like you
know you're pulling results out and then
it's those specific results which may or
may not look the same if you do it in
Oracle because it was left to be more of
a
a logical approach but there's
definitely some you know there's
definitely stuff like that that
structurally could make it easier to uh
maintain and extend
other good questions and comments
going once
all right hearing none
so we learned uh there is value which I
think we probably knew it before we came
in here there's some very good value to
being able to synchronize databases uh
particularly essentially on the Fly
uh they can also be tedious and
complicated that's why the best solution
is to consider these things from the
start and to with your databases also
have just like you would any other
source code a uh some development
procedures and standards that say this
is how we do it this is how we Version
Control it this is how we store it this
is how we propagate it so that
bringing in a new developer it's just a
matter of say Hey you know go to this
repository download this stuff execute
these things and boom you're off and
running uh particularly when you get in
the ideas of testing and regression
testing then it it may be where it's
just like hey you know go load this
database kick off these regression tests
part of what they do is they build out
all your data and you're you're off and
running and if you're in that kind of
environment it's actually really nice to
be able to
essentially create on the fly from
scratch a database that's got enough
data to do some testing to do some
development and then it can wipe it out
afterwards or you can utilize it to do
your uh your basic you know development
and and have something that's data on
the back end that's small and not you
know burying your your whatever your
storage devices
there's also levels of synchronization
and modeling that you you need to think
about is do I care about
um synchronizing to development my
indexes and and some of the things that
are really more performance related uh
do I need all the data or just some of
the data
can I just make it up or do I really
want to pull data from my source
um you can do it simply
and and not have as many of those
details that you're going to worry about
but if you do and it could be very quick
to do so and make it easy to do a quick
uh replication or you know shadow of a
database
but sometimes because you're not
limiting the data that's brought across
it could take up too much space or
it may be limiting because it doesn't
have you're not syncing the things that
are suddenly an issue because things
like foreign keys and uh indexes and
store procedures obviously can be
critical
to your application running correctly
so once again thank you for your time
for for going through all of this stuff
for you know just spending some time to
to work on becoming a better developer
if you have any questions or comments or
anything that you missed that you know
like just go through more you can always
reach us email info at developmentor.com
we have a contact us form out on
developreneur.com
YouTube there's a link here and there'll
be in the show notes YouTube is adding
things called handles and we have the
developreneur handle so as that which
would be like at developing or sort of
like a handle that you would have on
Twitter or something like that
as those become uh fully functional and
available that'll be probably an easier
way to get a hold of our page uh we're
out on Vimeo vimeo.com developmentor
we've got a Facebook page the developer
page there and twitter.com at
developmentor where we do our regular
posts and updates and things of that
nature
so thank you for your time again hope
you go out there and have yourself a
great day and I just remember you know
this is time you're investing in
yourself our goal is making every
developer better and you are helping not
only make every other developer better
but yourself as well
have a good day
thank you
Transcript Segments
10.7

thank you

18.89

[Music]

27.72

and it becomes which is why it became a

30.18

really fun combo project because while

32.82

there's a lot of little pythony things

34.98

that we ran into

36.96

uh really a lot of it is a is an

39.899

exploration of what

42.239

my sequel in particular

45.18

um stores and where it stores it about

47.579

the database itself and it it's

51.3

different if you're in Oracle or uh SQL

54.6

server or db2 but generally speaking the

58.14

problem the uh

60.96

the properties and details do exist

64.86

within the database itself so you can

66.659

query it almost in a reflection kind of

69.119

mode create about it so that you can

71.22

actually pull that and with some thought

74.04

you generate SQL and then execute that

76.979

SQL against your uh

80.04

whatever your target or your your

81.72

destination is and what you end up

84.06

getting is something where you know

86.52

probably what you're what you want to do

88.14

and what you want to think through if

89.759

you're going to synchronize your

90.78

databases how

93.06

how detailed do I want it to be is it

96.06

good enough for me to have just the

98.939

tables the tables the table structures

101.28

and the stored procedures and if the

103.439

tables are basically all empty of data

105.659

is that okay in some cases it is because

108.84

you can you can go in and maybe follow

111.18

it up with some little like quick uh

113.88

test script or something like that

115.34

particularly if you have automated

117

testing and regression testing then it

119.759

may be something where you say hey all I

121.14

need to do is just have an empty

122.88

database

124.38

that I'm going to create and then I'm

126.659

going to run this test script and it's

128.22

going to put some data in there for me

129.72

and I can maybe even script a couple of

131.7

bonus things there

133.379

and that becomes extremely useful

136.44

if you run in a situation where which

138.54

I've been to a couple of those where

140.54

you're at a job you're on a project and

143.64

you say hey I want to be able to like

146.22

see the I want to be able to create from

148.68

scratch the database and somebody says

151.02

oh that doesn't exist we don't have that

154.8

SQL

155.819

now you can in some cases you can do a

157.8

database dump

159.78

and get that SQL where you can do it

161.459

without the data

163.62

um but sometimes it's something like

165.18

this would be a little bit better you

166.68

know approach where you can bring it in

168.06

clean into your development environment

171.06

make some tweaks if you need to and then

173.28

you know export it or Point your

175.5

documentation tool towards it

179.7

so

181.739

that was sort of a you know there's a

183.9

lot of high level stuff there but the

185.58

you know with the key being to sort of

187.14

highlight

188.4

some of the things to think about if you

190.2

want to synchronize or if you're putting

194.04

together processes for promoting

195.659

databases through your your system

198.239

and so that being said questions

199.8

comments

203.159

so have you actually looked at something

205.26

called liquid base which might

208.62

kind of simplify that I don't know if

210.959

it's just Java based only but we use

213.659

Liquid based in that allows you to

216.12

basically build the

218.94

data or I guess the table structures in

221.519

that in the code so every time you

222.959

deploy it deploys the SQL

226.5

yeah there's I mean there are tools out

228.9

there that

230.879

do stuff like this

233.819

um

234.54

and it really is it's a

237.84

if you're doing it right from the start

239.459

you can like because liquid base is a

241.56

great tool for that and you can also do

243.06

reverse engineering uh like we mentioned

245.879

right Django is one if you're using some

248.58

of the tools out there like I think even

250.08

hibernate was one that had

253.26

um ways to generate a database I know

255.12

there's other you know object relational

256.68

mappers like that where

259.44

it may if you do it right from the start

261.6

then it shouldn't be an issue you should

263.759

have scripts and changes and you know

267.24

migration steps and things like that

269.28

that allow you to

271.56

maintain your database but this is also

274.5

dealing with data and things like that

276.18

that look like a liquid base is really a

278.1

structural it's much more structural

280.32

thing

281.46

and not a way to potentially copy data

285.18

so you know it's this is really like

287.16

taking well you can use the first bits

289.62

of this and use it strictly for

291.24

structural content the challenge becomes

294.12

when you want to do more than this when

296.4

you want to actually have data to move

298.62

from one place to another it's like how

300.419

do I how do I do that it's not like

303.06

copying a file from you know one system

305.94

to another because now you're like

308.759

grabbing just bits and pieces and not

311.34

the whole thing or at least you know if

313.62

you do the whole thing it's it's like

314.82

dump and restore if you want to do

316.44

pieces of it it gets a little more

317.759

complicated

322.38

yeah that makes sense yeah good point

324.419

though I mean because like there are

325.74

some really cool tools out there for

327.3

that piece of it

331.68

other questions and comments

334.039

only other thing is uh have you also

337.08

thought about moving your SQL out into

339.06

like a properties file and load it in

341.58

that way

345.8

uh I'm not sure I understand what do you

348.66

do so like within your python code you

351.36

had all the different selects inputs and

353.699

all that if you uh put that into like a

357

properties file you could inject your

358.68

SQL

359.759

uh wherever you wanted kind of like a

361.259

store procedure and then just uh update

363.66

tokens or update uh you know the inject

366.84

the data you need

368.52

uh that's sort of what it

370.74

that's sort of what it is if you um

375.66

did it come up okay so like for example

378.06

here these are

380.94

you could this this could easily be

383.4

that's that would be a way to do it

384.84

because right now and it's to get into a

387.3

little bit is it like this is the MySQL

389.46

synchronized script so it has uh my SQL

393.72

specific stuff

395.58

the thought being that if I had a Oracle

398.759

then it would be the same stuff but it

401.16

would be uh you know oracle synchronized

403.259

and then I'd do the Oracle specific code

405

within this now I could within here say

407.28

each of these and say hey this is going

409.8

to be a

412.319

um you know I could extract that out and

414.3

say hey this is you know property X for

417.96

my SQL and I could just swap out my

419.699

settings files

421.58

it's you could do that but it seems like

424.259

it's an extra level that doesn't uh that

427.319

wouldn't make I don't know I'm gonna say

429.18

I was gonna say it wouldn't make it as

431.16

readable

432.96

um because it's nice to be able to see

434.46

right here it's like oh here's what it's

436.08

doing you know this is where I'm getting

438

the data this isn't data I'm pulling

439.8

from it

441.479

um

442.56

and I'm not reusing these too terribly

445.259

often

446.639

um so it's

448.8

yeah it could be extracted out I'm not

451.56

sure that that's I'm not sure if I if I

454.02

see enough of a benefit for it other

456.36

than if you want to do it a little

458.4

differently as far as how you

461.16

um are able to abstract and set stuff up

463.5

I mean in this case I'm it's done

465.06

through like hey I've got I'll have the

466.62

thought is I would have different

467.52

classes for different databases versus

470.039

just different setting files for

472.08

different databases which would be

473.639

possible for itself as well

476.039

right no I was just looking at your

477.9

Source destination it's like you're

479.34

duplicating the SQL so why not just put

481.139

all the SQL in one class and that like

483.18

here here's all your

485.639

here's all the SQL

487.8

in one place and you just go read it

489.599

there and then you apply it wherever you

492

need to apply it that's true and that

494.4

may be

495.96

um

496.8

you know that maybe in particular

498.06

because it's like

499.979

it's usually in the same place but you

501.66

do see there are like duplicates here so

503.34

it's like the you know the really the

505.56

difference between these two are just

507.479

the name

509.52

um so it could be something like just

511.08

you know slap that in there and then

512.64

give it a different uh like create that

514.8

as a template and then slap the names in

517.56

um and maybe it could be reused in

519.06

places and that may be something that's

520.8

part of the cleanup that ends up coming

522.18

as we get further into it is it maybe

523.979

like hey let's go ahead and take some of

525.839

these things where we see repeated SQL

528.6

and clean that up and make that you know

532.08

give that a Slicker little interface so

534.3

good point yeah the reason I mentioned

536.279

that is because you said like that's for

538.32

my sequel well if you want to go to

539.76

Oracle some of those queries might

541.26

change but you could essentially take

542.76

the same queries just tweak them for

544.38

Oracle and then just apply it to a

546.42

different utility

548.279

yeah and that may be something too where

550.38

it's one of those where it's useful sort

552.24

of like a um a resource bundle kind of

554.76

approach is that even though it's

556.32

different classes and then if you take

558.06

the

559.68

um if you take those seek those SQL

561.899

things and say hey these These are the

564.779

quick and take all those and Abstract

566.22

them up to you know like up on the class

567.959

level and hear you know where you'd have

570

like you know uh uh so you'd have like

573.36

well like SQL one SQL two whatever it is

576.72

whatever you call those and so then if

578.82

you're when you

580.019

create the Oracle synchronized class

582.54

then you just you see right there here's

584.64

where all my SQL is so I can just go

586.019

right here and go through my say the SQL

588.72

and change it over to use Oracle stuff

591.48

but the thought also is that Oracle or

594.24

SQL Server is going to be different

595.62

enough that you're probably going to

597.6

have to change several of the things

599.04

that are done in particular here because

601.74

you're going through and you're like you

603.18

know you're pulling results out and then

604.44

it's those specific results which may or

607.56

may not look the same if you do it in

609.3

Oracle because it was left to be more of

611.279

a

612.42

a logical approach but there's

614.88

definitely some you know there's

616.2

definitely stuff like that that

617.399

structurally could make it easier to uh

620.339

maintain and extend

624.839

other good questions and comments

631.68

going once

633.48

all right hearing none

636.72

so we learned uh there is value which I

640.5

think we probably knew it before we came

641.76

in here there's some very good value to

644.82

being able to synchronize databases uh

647.519

particularly essentially on the Fly

650.24

uh they can also be tedious and

652.86

complicated that's why the best solution

655.2

is to consider these things from the

658.2

start and to with your databases also

661.079

have just like you would any other

663.06

source code a uh some development

666.6

procedures and standards that say this

669.12

is how we do it this is how we Version

671.339

Control it this is how we store it this

674.339

is how we propagate it so that

677.94

bringing in a new developer it's just a

680.16

matter of say Hey you know go to this

682.079

repository download this stuff execute

684.24

these things and boom you're off and

685.86

running uh particularly when you get in

689.04

the ideas of testing and regression

690.72

testing then it it may be where it's

692.399

just like hey you know go load this

694.26

database kick off these regression tests

696.36

part of what they do is they build out

697.98

all your data and you're you're off and

699.779

running and if you're in that kind of

701.579

environment it's actually really nice to

703.62

be able to

705.26

essentially create on the fly from

707.76

scratch a database that's got enough

709.5

data to do some testing to do some

711.959

development and then it can wipe it out

713.459

afterwards or you can utilize it to do

715.38

your uh your basic you know development

718.019

and and have something that's data on

720.899

the back end that's small and not you

723.66

know burying your your whatever your

725.64

storage devices

727.459

there's also levels of synchronization

729.779

and modeling that you you need to think

731.399

about is do I care about

735.36

um synchronizing to development my

737.579

indexes and and some of the things that

740.1

are really more performance related uh

743.22

do I need all the data or just some of

746.16

the data

747.54

can I just make it up or do I really

749.16

want to pull data from my source

753.12

um you can do it simply

755.1

and and not have as many of those

757.86

details that you're going to worry about

759.18

but if you do and it could be very quick

761.279

to do so and make it easy to do a quick

763.98

uh replication or you know shadow of a

766.98

database

769.32

but sometimes because you're not

772.5

limiting the data that's brought across

774.3

it could take up too much space or

777.42

it may be limiting because it doesn't

779.16

have you're not syncing the things that

781.56

are suddenly an issue because things

783.779

like foreign keys and uh indexes and

787.2

store procedures obviously can be

789.48

critical

791.579

to your application running correctly

796.079

so once again thank you for your time

798.06

for for going through all of this stuff

800.04

for you know just spending some time to

801.72

to work on becoming a better developer

805.139

if you have any questions or comments or

807.66

anything that you missed that you know

809.22

like just go through more you can always

810.959

reach us email info at developmentor.com

813.3

we have a contact us form out on

815.88

developreneur.com

817.74

YouTube there's a link here and there'll

819.899

be in the show notes YouTube is adding

822.54

things called handles and we have the

824.94

developreneur handle so as that which

828.24

would be like at developing or sort of

829.92

like a handle that you would have on

831

Twitter or something like that

832.56

as those become uh fully functional and

836.22

available that'll be probably an easier

838.38

way to get a hold of our page uh we're

840.779

out on Vimeo vimeo.com developmentor

844.079

we've got a Facebook page the developer

846.06

page there and twitter.com at

848.639

developmentor where we do our regular

850.92

posts and updates and things of that

852.72

nature

854.04

so thank you for your time again hope

856.98

you go out there and have yourself a

858.18

great day and I just remember you know

861

this is time you're investing in

862.44

yourself our goal is making every

864.12

developer better and you are helping not

868.079

only make every other developer better

869.519

but yourself as well

871.38

have a good day

887.24

thank you