Flask MVP is done and it has been a rewarding journey. There is no visible speed improvement in the local development environment, but I hope learning about PostgreSQL and deploying it live will pay off in the future. My Flask MVP now runs on the PostgreSQL database. I am lazy to figure out how to do it programmatically so I just use DBeaver to import data by copy-pasting data from CSV. The last thing to do is to migrate data from SQLite to PostgreSQL DB. Fortunately, there is a free PostgreSQL client for mac called DBeaver. Now I need to check, that tables and columns have been actually created.Īnd I don’t want to use PSQL commands so I need some UI clients to manage PostgreSQL. INFO Running upgrade -> 88b94cf131e9, empty message Now apply migrations to the PostgreSQL database. Versioned database migration files have been created. Now create new migration files by typing this into python shell. #app.config = 'sqlite:///./app.sqlite'Īpp.config='postgresql://localhost/mydb'īefore continuing further, I archive the existing migrations folder and SQLite file into the new temporary folder. Integrating PostgreSQL into Flask is as easy as changing database connection URI in our _init_.py file. pipenv install psycopg2 Flask-SQLAlchemy Flask-Migrate, psycopg2-binary Then install necessary database adapters for python and Flask. createdb mydb Installing PostgreSQL python dependencies Ok, this command will create a database correctly. With an argument other than "/usr/local/var/postgres”. The directory "/usr/local/var/postgres" or run initdb If you want to create a new database system, either remove or empty initdb: directory "/usr/local/var/postgres" exists but is not empty This doesn’t seem like the right command. Maybe I need to create PostgreSQL manually. Home is the name of my mac account and main folder. psql: FATAL: database "home" does not exist Try again SQL command, but unsuccessfully. => Successfully started `postgresql` (label: ) Maybe PostgreSQL is not up and running? brew services start postgresql Is the server running locally and acceptingĬonnections on Unix domain socket "/tmp/.s.PGSQL.5432”? psql: could not connect to server: No such file or directory Type this to command lien to access PostgreSQL commands. Now create a new database, that will replace our old SQLite database. So without further ado, let’s start with PostgreSQL installation. Migrating from SQLite to PostgreSQL Installing PostgreSQL And migrate database objects and data from SQLite to the new PostgreSQL database. Today, I will try to set up PostgreSQL on my mac development environment. PostgreSQL is positively reviewed across all areas, there is an existing library for Flask so I told myself why not. So after googling around for the best free open source SQL database on the market, I decided to go with PostgreSQL. I thought I would stick to known solutions, but hey, this is a learning exercise right? PostgreSQL as the best DB for Flask In the past, I always used an apache stack with a built-in MySQL database. Those are the main SQLite cons, speed performance, concurrency, and security. You want it to serve multiple parallel read-write operations. To scale your Flask minimum viable product and prepare it for huge upcoming traffic, you want your SQL database to be lightning fast. Well up until now, I always followed Django or Flask tutorials, which used SQLite as the main database backend. And that is doing a migration of database backend from SQLite to PostgreSQL. But there is one final task, that I planned to do for a long long time. That means, that the minimum viable product is ready to go live. I managed to finish About us page design-wise in last the two sessions. Today is the 21st day of me building Flask MVP from scratch. Part 12: Building MVP with Flask Day 18-21 – Migration from SQLite to PostgreSQL.Part 11: Building MVP with Flask Day 10-17 – Adding Flask routes and views.Part 10: Building MVP with Flask Day 9 – Sorting with ORM queries. Part 9: Building MVP with Flask Day 8 – Serving static files.Part 8: Building MVP with Flask Day 7 – Left join with SQLAlchemy.Part 7: Building MVP with Flask Day 6 – Using Queryset to retrieve and render data.Part 6: Building MVP with Flask Day 5 – Setup SQLite database.Part 5: Building MVP with Flask Day 4 – Using children templates.Part 4: Building MVP with Flask Day 3 – Adding Bootstrap 4.Part 3: Building MVP with Flask Day 2 – Jinja2 template basics.Part 2: Building MVP with Flask Day 1 – Dev setup.Part 1: Building MVP with Flask Day 0 - Project goals.This post is part of the series Building an MVP with Flask.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |