#100DaysOfCode in Python Transcripts
Chapter: Days 97-99: Building JSON APIs
Lecture: Migrating our SQLAlchemy models

Login or purchase this course to watch this video and the rest of the course contents.
0:00 All right, it's time to move some existing code and data
0:04 over here, just from our previous persistent
0:06 Rock Paper Scissors.
0:08 Remember, one of the things that we used in the 15-way
0:10 Rock Paper Scissors was we needed this CSV file to
0:14 basically determine who wins and who loses
0:18 for any combination of those 15-way battles.
0:22 Let's paste that over here.
0:24 We're going to have our CSV file that tells us that,
0:27 and we'll also have this DB folder thing,
0:29 we already saw that.
0:30 This just tells us easy way to get back to this location
0:33 base and generate either read or writable files here.
0:36 We're going to put our SQLAlchemy data in there as well.
0:40 That has to do with reading the data in the games.
0:43 The other thing we had was lots of stuff around SQLAlchemy
0:45 defining the models and saving and querying who played
0:50 a game, does the player exist, all of that stuff.
0:52 We're just going to take that and drop it in here.
0:55 We're not really going to change that hardly at all.
0:59 But I'm going to make this folder called game_logic,
1:02 and you can see we have our SQLAlchemy declarative base.
1:05 We have our move.
1:06 This literally is the same thing as before.
1:08 It's not changed at all.
1:09 We have our game decider, our GameService.
1:12 These are all basically the same.
1:14 I had to add just a couple of methods to GameService,
1:16 but they're super trivial, like find a roll by id,
1:18 and things like that.
1:20 Nothing important or new here,
1:24 other than this only change really is that this game,
1:27 it used to have all the loop logic and all that stuff,
1:31 and now we need to really separate that.
1:33 That's going to go down into the client,
1:35 but there's still a little bit of work that our game class
1:37 is going to do.
1:38 We'll have this over here.
1:41 There we've moved in the code from our game previously.
1:44 Now our job is to integrate it into our web application.