Skip to content

Commit 5c57930

Browse files
committed
first
1 parent dcfe3b2 commit 5c57930

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from flask import Flask
2+
from flask_sqlalchemy import SQLAlchemy
3+
from flask_migrate import Migrate
4+
import config
5+
6+
app = Flask(__name__)
7+
app.config.from_object(config.SQLiteConfig) # Choose SQLiteConfig, MySQLConfig, or PostgreSQLConfig
8+
9+
db = SQLAlchemy(app)
10+
migrate = Migrate(app, db)
11+
12+
# Register models
13+
import models
14+
15+
# Route for testing
16+
@app.route('/')
17+
def index():
18+
return "Flask-Migrate setup is working!"
19+
20+
if __name__ == '__main__':
21+
app.run(debug=True)

config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os
2+
3+
class Config:
4+
SQLALCHEMY_TRACK_MODIFICATIONS = False
5+
6+
class SQLiteConfig(Config):
7+
SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
8+
9+
class MySQLConfig(Config):
10+
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://username:password@localhost/dbname'
11+
12+
class PostgreSQLConfig(Config):
13+
SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@localhost/dbname'

models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from app import db
2+
3+
class User(db.Model):
4+
id = db.Column(db.Integer, primary_key=True)
5+
username = db.Column(db.String(80), unique=True, nullable=False)
6+
email = db.Column(db.String(120), unique=True, nullable=False)
7+
8+
def __repr__(self):
9+
return f'<User {self.username}>'

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Flask==2.3.2
2+
SQLAlchemy==2.0.23
3+
Flask-Migrate==4.0.4
4+
pymysql==1.0.3 # For MySQL support
5+
psycopg2-binary==2.9.7 # For PostgreSQL support

0 commit comments

Comments
 (0)