I've used Raiway.app to deploy this code: https://github.com/lucascvalle/Ninja-JutsuBattle-Website It's a Python/Flask Web Application that uses Flask for its backend and CSS and HTML for a basic view of the website.
First i've created a PostgreSQL Project and then incorporated my Github code in it. Since then i've changed only a few things in my init.py and my routes.py to adapt the online database.
After a successfull deploy of the website I could register and login an user and even create posts. But the PostgreSQL screen keep on showing that there are no tables at all. Even though i need the existence of a table 'user' and 'post'. I've connected the pgAdmin 4 to the railway database but it also shows like there are no tables.
I've done the following query on railway:
SELECT user FROM information_schema.tables WHERE table_schema = 'public';
It ran successfully but returned as "No data to display, table is empty." even after I register an user and login successfully.
I want to be able to fully access my database through pgAdmin 4 so I can insert the data for the other tables and create the objects from the classes Jutsu, Element, KekkeiGenkai, KekkeiGenkaiAbility so the User could be able create an "Ninja" object.
PS: I know that in my init.py file has the following code:
if os.getenv("DATABASE_URL"):
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("DATABASE_URL")
else:
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///ninjajutsubattle.db'
database = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'alert-info'
from ninjajutsubattle import models
engine = sqlalchemy.create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
inspection = sqlalchemy.inspect(engine)
if not sqlalchemy.engine.reflection.Inspector.has_table(inspection, 'user'):
with app.app_context():
database.drop_all()
database.create_all()
print('Database created')
else:
print('Database already exists')
And I know that the code will drop my whole database everytime it gets deployed. I would also like a solution for that because I was taught this way but for me it just seems wrong.