Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate v0 features to v1 API #70

Closed
hwakabh opened this issue Jan 20, 2024 · 3 comments · Fixed by #72
Closed

Migrate v0 features to v1 API #70

hwakabh opened this issue Jan 20, 2024 · 3 comments · Fixed by #72
Assignees
Labels
chore Changes not related to application logics enhancement New feature or request

Comments

@hwakabh
Copy link
Owner

hwakabh commented Jan 20, 2024

AsIs

With current code basis, we have 2 versions of API, v0 and v1, and some core logics are still implemented as back-porting API in v0 API.
This is not better way for future maintenance and code readability, so should be migrated within v1, which is current latest one.

ToDo

  • Add models for handling with MySQL
    • Since function get_destination_from_skyscanner_by_random() and get_near_airport() seem to be depended on MySQL connection, we have to implement FastAPI database model first.
  • Migrate app/api/v0/cruds.py to v1 API, since all functions related to MySQL have been implemented in previous endpoint

(Optional) Acceptance Criteria

  • Still application will have been started up locally
  • Tests/Build pipeline will be passed
@hwakabh hwakabh self-assigned this Jan 20, 2024
@hwakabh hwakabh added enhancement New feature or request chore Changes not related to application logics labels Jan 20, 2024
@hwakabh
Copy link
Owner Author

hwakabh commented Jan 21, 2024

Regarding seeding data from airport.csv, note that we have to make some small modifications for current code bases.
As current SQL insert.sql for seeding data seems to insert data from loading CSV file, but this requires to add configurations for both server-side and client-side of MySQL.

So, by default we got the following errors even though adjusting file path of CSV.

% mysql --user=root --password=root --host=0.0.0.0 < sql/import.sql                 
ERROR 3948 (42000) at line 27: Loading local data is disabled; this must be enabled on both the client and server sides

This is because MySQL have disabled to load data by default with param local_infile.

-- % mysql --user=root --password=root --host=0.0.0.0 --execute='select @@local_infile'
+----------------+
| @@local_infile |
+----------------+
|              0 |
+----------------+

So we need to fix this with updating defaults:

# Update default parameters
% mysql --user=root --password=root --host=0.0.0.0 --execute='set persist local_infile = 1;'
% mysql --user=root --password=root --host=0.0.0.0 --execute='select @@local_infile'        
+----------------+
| @@local_infile |
+----------------+
|              1 |
+----------------+

# Load data from CSV
% mysql --user=root --password=root --host=0.0.0.0 --local-infile=1 < sql/import.sql

# Validate
% mysql --user=root --password=root --host=0.0.0.0 --execute='select count(*) from rt.airport;'  
+----------+
| count(*) |
+----------+
|     7698 |
+----------+
% mysql --user=root --password=root --host=0.0.0.0 --execute='select * from rt.airport limit 10;'
+----+---------------------------------------------+--------------+------------------+------+------+-----------+------------+----------+----------+------+----------------------+---------+-------------+--------+
| id | Name                                        | City         | Country          | IATA | ICAO | Latitude  | Longitude  | Altitude | Timezone | DST  | Tz database time     | zone    | Type        | Source |
+----+---------------------------------------------+--------------+------------------+------+------+-----------+------------+----------+----------+------+----------------------+---------+-------------+--------+
|  1 | Goroka Airport                              | Goroka       | Papua New Guinea | GKA  | AYGA | -6.081690 | 145.391998 | 5282     | 10       | U    | Pacific/Port_Moresby | airport | OurAirports | NULL   |
|  2 | Madang Airport                              | Madang       | Papua New Guinea | MAG  | AYMD | -5.207080 | 145.789001 | 20       | 10       | U    | Pacific/Port_Moresby | airport | OurAirports | NULL   |
|  3 | Mount Hagen Kagamuga Airport                | Mount Hagen  | Papua New Guinea | HGU  | AYMH | -5.826790 | 144.296005 | 5388     | 10       | U    | Pacific/Port_Moresby | airport | OurAirports | NULL   |
|  4 | Nadzab Airport                              | Nadzab       | Papua New Guinea | LAE  | AYNZ | -6.569803 | 146.725977 | 239      | 10       | U    | Pacific/Port_Moresby | airport | OurAirports | NULL   |
|  5 | Port Moresby Jacksons International Airport | Port Moresby | Papua New Guinea | POM  | AYPY | -9.443380 | 147.220001 | 146      | 10       | U    | Pacific/Port_Moresby | airport | OurAirports | NULL   |
|  6 | Wewak International Airport                 | Wewak        | Papua New Guinea | WWK  | AYWK | -3.583830 | 143.669006 | 19       | 10       | U    | Pacific/Port_Moresby | airport | OurAirports | NULL   |
|  7 | Narsarsuaq Airport                          | Narssarssuaq | Greenland        | UAK  | BGBW | 61.160500 | -45.425999 | 112      | -3       | E    | America/Godthab      | airport | OurAirports | NULL   |
|  8 | Godthaab / Nuuk Airport                     | Godthaab     | Greenland        | GOH  | BGGH | 64.190903 | -51.678101 | 283      | -3       | E    | America/Godthab      | airport | OurAirports | NULL   |
|  9 | Kangerlussuaq Airport                       | Sondrestrom  | Greenland        | SFJ  | BGSF | 67.012222 | -50.711603 | 165      | -3       | E    | America/Godthab      | airport | OurAirports | NULL   |
| 10 | Thule Air Base                              | Thule        | Greenland        | THU  | BGTL | 76.531197 | -68.703201 | 251      | -4       | E    | America/Thule        | airport | OurAirports | NULL   |
+----+---------------------------------------------+--------------+------------------+------+------+-----------+------------+----------+----------+------+----------------------+---------+-------------+--------+

@hwakabh
Copy link
Owner Author

hwakabh commented Jan 21, 2024

Also, the raw seeds data of airport.csv seems to be originated from the ones from openflights data, and the descriptions for each field is documented here.
With comparing both, there is no differences even though it have been passed for 4 years, so we need not to update this raw data, and can use them as seeds data.

@hwakabh
Copy link
Owner Author

hwakabh commented Jan 21, 2024

Also regarding FastAPI database model, FastAPI would basically expect to use with ORM like SQLAlchemy and its dialects for backend databases.
As described in official docs, for usage with mysql-connector-python, which have been already installed as deps for this app, we should use dialect like:

mysql+mysqlconnector://<user>:<password>@<host>[:<port>]/<dbname>

So we have to configure this in database.py for apps to determine what database they should connect to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes not related to application logics enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant