From 1f2f6070efce9cb78e3a697cb85a020e1d54b60c Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Thu, 11 Apr 2024 01:48:41 -0300 Subject: [PATCH] Started creating the api --- .gitignore | 2 + requirements.txt | 15 +++ server/.env | 8 ++ .../__pycache__/controllers.cpython-310.pyc | Bin 0 -> 1692 bytes .../Film/__pycache__/models.cpython-310.pyc | Bin 0 -> 1123 bytes server/Film/__pycache__/urls.cpython-310.pyc | Bin 0 -> 944 bytes server/Film/controllers.py | 44 +++++++ server/Film/models.py | 17 +++ server/Film/urls.py | 15 +++ .../__pycache__/controllers.cpython-310.pyc | Bin 0 -> 1695 bytes .../__pycache__/models.cpython-310.pyc | Bin 0 -> 989 bytes .../__pycache__/urls.cpython-310.pyc | Bin 0 -> 1086 bytes server/FilmManufacturer/controllers.py | 40 +++++++ server/FilmManufacturer/models.py | 13 ++ server/FilmManufacturer/urls.py | 15 +++ server/__init__.py | 0 server/__pycache__/__init__.cpython-310.pyc | Bin 0 -> 156 bytes server/__pycache__/app.cpython-310.pyc | Bin 0 -> 1356 bytes server/__pycache__/config.cpython-310.pyc | Bin 0 -> 1258 bytes server/app.py | 43 +++++++ server/config.py | 29 +++++ server/migrations/README | 1 + .../__pycache__/env.cpython-310.pyc | Bin 0 -> 2824 bytes server/migrations/alembic.ini | 50 ++++++++ server/migrations/env.py | 113 ++++++++++++++++++ server/migrations/script.py.mako | 24 ++++ server/migrations/versions/724351b0562f_.py | 44 +++++++ .../__pycache__/724351b0562f_.cpython-310.pyc | Bin 0 -> 1195 bytes 28 files changed, 473 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100644 server/.env create mode 100644 server/Film/__pycache__/controllers.cpython-310.pyc create mode 100644 server/Film/__pycache__/models.cpython-310.pyc create mode 100644 server/Film/__pycache__/urls.cpython-310.pyc create mode 100644 server/Film/controllers.py create mode 100644 server/Film/models.py create mode 100644 server/Film/urls.py create mode 100644 server/FilmManufacturer/__pycache__/controllers.cpython-310.pyc create mode 100644 server/FilmManufacturer/__pycache__/models.cpython-310.pyc create mode 100644 server/FilmManufacturer/__pycache__/urls.cpython-310.pyc create mode 100644 server/FilmManufacturer/controllers.py create mode 100644 server/FilmManufacturer/models.py create mode 100644 server/FilmManufacturer/urls.py create mode 100644 server/__init__.py create mode 100644 server/__pycache__/__init__.cpython-310.pyc create mode 100644 server/__pycache__/app.cpython-310.pyc create mode 100644 server/__pycache__/config.cpython-310.pyc create mode 100644 server/app.py create mode 100644 server/config.py create mode 100644 server/migrations/README create mode 100644 server/migrations/__pycache__/env.cpython-310.pyc create mode 100644 server/migrations/alembic.ini create mode 100644 server/migrations/env.py create mode 100644 server/migrations/script.py.mako create mode 100644 server/migrations/versions/724351b0562f_.py create mode 100644 server/migrations/versions/__pycache__/724351b0562f_.cpython-310.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2b838e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv +/instance \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..960e762 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,15 @@ +alembic==1.13.1 +blinker==1.7.0 +click==8.1.7 +Flask==3.0.3 +Flask-Migrate==4.0.7 +Flask-SQLAlchemy==3.1.1 +greenlet==3.0.3 +itsdangerous==2.1.2 +Jinja2==3.1.3 +Mako==1.3.3 +MarkupSafe==2.1.5 +python-dotenv==1.0.1 +SQLAlchemy==2.0.29 +typing_extensions==4.11.0 +Werkzeug==3.0.2 diff --git a/server/.env b/server/.env new file mode 100644 index 0000000..ea2f27d --- /dev/null +++ b/server/.env @@ -0,0 +1,8 @@ +# Configuration Mode => development, testing, staging, or production +CONFIG_MODE = development + +# POSTGRESQL_DATABASE_URI => 'postgresql+psycopg2://user:password@host:port/database' +DEVELOPMENT_DATABASE_URL = 'sqlite:///DevDB.db' +TEST_DATABASE_URL = 'sqlite:///TestDB.db' +STAGING_DATABASE_URL = 'sqlite:///StagingDB.db' +PRODUCTION_DATABASE_URL = \ No newline at end of file diff --git a/server/Film/__pycache__/controllers.cpython-310.pyc b/server/Film/__pycache__/controllers.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7d034cdfb6f6c72d275561a2bfebcd69502ad792 GIT binary patch literal 1692 zcmZux&2HO95Z>iKDN1(I*0ox+P|_a4OY{P1QKUi(AF3Mgr4U-M40mNyCPig;X+wd0 zO0Ri>q5yr&EA6!>ze3SNXO@-!VhS40{?5$zeZ#unj|e=!Jl&hmTtfcF!R^O_!FTYN zzk*?e(UMejMk{M(Q5;*PJ+qn3oYJY>nG16+^GdJsXFm8o3;rOpfQ2lAcgT7yhIhpJ zYyj^b+hM!#j+u2tl1En%fh3mp1%KUeskFb4^|F|+r&pLoLbb(SUD3{UekjT+#}nJf z1_vr2-@{)%2cyV>w$>%NAjjl_ZpeiE7G78z+S(hdbuP&zrQ~&}+zow8kH~vEO+4Yl zIqgDtvDS80mfFi!E52mfQ}v|CmB1*8t=&0WYt# z8>zChx++ArWZC#o)C;a^ImXl{FVmMu)GRW&Gfh;HgE}MgXj(dUy|z=S{V<%qp(!gQK5yc-Y93^soW^2359f=2@;9 z!NtKOal}WEiTD`JCt&p6{4_;Ce!8_UEm#r@BpqK)UesQMwIV;$kK5Bn-UZ|7N!Q`7a z!_j#rM}k-N8D}HeSmvTz?Pant eJr=xxqfN=bMF#?%@4e5jXtx6d>&NTvNDzd6Sz~p%U~GY?x3Ez} zF-HPN7+aliB1l9)cc{x9;YKb-?-6ZK?*dVexzonE6M3{bL_L22_fZdIa8N8KO5Ij5G5d(I#-Rz1E2Lbse6sD zapd3IjoM!O&kpWvzyYmAJ%}Pv2(eJAK!`<>SED4=m1MG? zQPZ)w`zub3r4^#YV{Xk_Ui7rsW9=p0Y+l+P;h@lCosd zglWMmk;k@TC7;4kUFK4IR!1(u+Mw5o0vy;xt(8Ovy^itYI8OwNV-v(Nlv;7ChjBcs z623f+2llTzE#ss^CWZ5|X0Q7c8 z$FWVlItno$gp$GQXGN|iS!p^W2w5E=`SQLs`wYt_ZGUn}9yDkDK6;Kj_1DGgIK=ho zL9b~7HRB0SCrr$10;L@);{b`vt{VIHb?WdX_QNd3-&k_8X$MmIu!ShZA?cDo=)EO2 literal 0 HcmV?d00001 diff --git a/server/Film/__pycache__/urls.cpython-310.pyc b/server/Film/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9111f4ad08c4c4260da9d12d2a2ed5f5b51c8360 GIT binary patch literal 944 zcmZuvO>Yx15VgG@*?e{zXau51E_-3`RaI4`feR{;5-xj*Re4oU`@gO0Qhe|NYUUjI+m`?!)vATxz_x{gLqp?}sB`E1145 zsG0!#ssa1g_NbTEX|%u;FNusac|gN0CKkuq15E8nyc^lH-^!MCi7%mn3AgQK2!)z; zKaf0v7~Jp6^tKQzos~-G>q5+Ben<0kAd3alg>rPSuf|vTWXbMms+e3e>9T1lxq7ww zWKQ;iR^(G~n}St{$x|$kZEzoNAD^Cs@Z&kXNIb{Zc!Lik6JGb<^+){)jOnjIycglj zg1rcJO+MR|sL0UOUM1sMVP0r|n{m?kJ88PMjeKHV5;%Qi2NDsuIyhKv7|M?1K`I&B ziaFiy!fy1tNxQj%_U`3f(#1V2Pb|JkS|*tCTrIcPfhMMT*gAC>%s(tlAd6BnC!T9n f;o=792u0_jpe1J)AeMs1v`~wj;+QmW?04`V96R8- literal 0 HcmV?d00001 diff --git a/server/Film/controllers.py b/server/Film/controllers.py new file mode 100644 index 0000000..5b2ba20 --- /dev/null +++ b/server/Film/controllers.py @@ -0,0 +1,44 @@ +from flask import request, jsonify +import uuid +from ..app import db +from .models import Film + +def list_all_films_controller(): + films = Film.query.all() + response = [] + for film in films: response.append(film.toDict()) + return jsonify(response) + +def create_film_controller(): + request_form = request.form.to_dict() + print(request_form) + new_film = Film( + name = request_form['name'], + ISO = request_form['ISO'], + Push_Pull = request_form['Push_Pull'], + fk_FilmManufacturer_id = request_form["manufacturerID"] + ) + db.session.add(new_film) + db.session.commit() + response = Film.query.all() + return(jsonify(request_form)) + +def retrieve_film_controller(film_id): + response = Film.query.get(film_id).toDict() + return jsonify(response) + +def update_film_controller(film_id): + request_form = request.form.to_dict() + film = Film.query.get(film_id) + film.name = request_form['name'] + film.ISO = request_form['ISO'] + film.Push_Pull = request_form['Push_Pull'] + film.fk_FilmManufacturer_id = request_form["manufacturerID"] + db.session.commit() + response = Film.query.get(film_id).toDict() + return jsonify(response) + +def delete_film_controller(film_id): + Film.query.filter_by(id=film_id).delete() + db.session.commit() + return f"Film with ID={film_id} was removed successfully" \ No newline at end of file diff --git a/server/Film/models.py b/server/Film/models.py new file mode 100644 index 0000000..7dfd6db --- /dev/null +++ b/server/Film/models.py @@ -0,0 +1,17 @@ +from sqlalchemy import inspect +from datetime import datetime + +from ..app import db + +class Film(db.Model): + id = db.Column(db.Integer(),primary_key=True,nullable=False,unique=True, autoincrement=True) + name = db.Column(db.String(255)) + ISO = db.Column(db.String(10)) + Push_Pull = db.Column(db.String(10)) + fk_FilmManufacturer_id = db.Column(db.Integer(),db.ForeignKey("film_manufacturer.id")) + filmmanufacturer = db.relationship("FilmManufacturer",back_populates='films') + def toDict(self): + return { + c.key: getattr(self,c.key) for c in inspect(self).mapper.column_attrs + } + diff --git a/server/Film/urls.py b/server/Film/urls.py new file mode 100644 index 0000000..f110829 --- /dev/null +++ b/server/Film/urls.py @@ -0,0 +1,15 @@ +from flask import request + +from ..app import app +from .controllers import list_all_films_controller,create_film_controller,retrieve_film_controller,update_film_controller,delete_film_controller + +@app.route("/Films",methods=["GET","POST"]) +def list_all_create_films(): + if request.method == 'GET' : return list_all_films_controller() + if request.method == 'POST' : return create_film_controller() + +@app.route("/Films/",methods=["GET","PUT","DELETE"]) +def retrieve_update_delete_Films(film_id): + if request.method == 'GET' : return retrieve_film_controller(film_id) + if request.method == 'PUT' : return update_film_controller(film_id) + if request.method == "DELETE": return delete_film_controller(film_id) diff --git a/server/FilmManufacturer/__pycache__/controllers.cpython-310.pyc b/server/FilmManufacturer/__pycache__/controllers.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..05fe57655cb3be43bc6b233e070f90eaa3b27e52 GIT binary patch literal 1695 zcmah}&2Aev5GJ|*@;Z@|w5f}<6^aC?F3}4lMd2Dnd#F&rH=)I1v!t9=cD2foYeRv2 zO0Ri>qQLr?OCN~Wp8N{Ev@=vJD|V0)&~S!J4mscVjhfxv9>eiqe1G~^z}VjuY!89K zclgu4qLEDUiq(9=YcUa=Vo`Y$PkPd?{5qHfxE9E;3hQVRp&!ZkcQ%P-B6~O|az~~( z_vEg;h4YTQE&Dj9QXH}2-UZ&khQdamUbadb8_jexFQ?1#1-)X(t&q<_jK;7T@5DJfW5?`_uh=2`Ejbe_-gzt0`RDAMbM`VZ z!HU1;N9-*h4?~FXoDJ|Pu(V!YRW{5Q3pJNEG|gdI7@%8*p52?`Q|hg!Xd8pli)OBs z?O*@+mO&rS{c|*W-qdPz+-j4bG<6C2T;`)+pqVMt=n<87c#s|B#S6T0q!pYfaI4!z zkBVk)ps6Ya`tf3EA62C`8NM~Ueyz@~wuX4Wj?whE&p+cahdUVD0FcUa0RD*16@bQD zvDXNf@mDB^eU!i(e#T8O3%h8=2}tM1=ZyBulCFoa3$sI~kY;ae{dr!iA&0w|cbEc^ zYyD{hwT(=ZNrcu03n;NNq5z0U8)>C=+02m%i3}7?U6%$D`c4AA@O zkbqmXpEy{XJ@o9?1*qJp8=JRKOL3njpn8ay;2{tHO}!qc2p-^aLCU-wRMQ5(0S0UQ zRw%U2Lp(U5hf*V~){+C_f~$aliTQ6yTu(Jf{FL z-ew-|VOIErjAPqT`UQm~4@W-GGhv^M!^1)0!_Hb&=~5W>2b12P9tz$c(?3@!U+q&*Z+GwD zv^38LKOH`OwLdt`^#D}eoG3ZaZBd}wr)^a&htU-*HbL@@g6!GShEi1ueQJ&?e6Xn; zD%aJ$-uy9jKf*jt33m{Ll*2=ehr2eIR=IxRTGT1f`fXcEY{JE2-IrnAU~;{FBz1@D q1t%m2qD!>ZZSG~R<>DuJw5`;)1g&eVK8x|{l*b|tsE64VLx%rY9ou1%0+g<7bdJ)A?T6d#&4@)-g2`>TU{4b zE_ul-eR~I>jB6X2!32D{)D8%)AJP0IYwD&IRCASslK0ET&L30HA^3_WmI%2BHM&IS zc!p(6}isqve~kCNm;}`8esqK)2n}_AL@D!iiew`&Z$sa!@p+} zM_RtdFKN?oY2v&VZCPcOiIP@=4t^g!?kf9cD-d@>BOKYGPyRD>oWv%~vWk{G%S@DI zK%o^jj>j7px<_omN)MbhWi<-XQ#`=yIL6)nIPp!S=7Ng+n3s!Q2M1*6v3Lho>#nkI_^`DJ RH+v>q_NsMC#3&{kYx15VgI#`A)k@p%=Ii6~SJ}9aR-74O~izlyKQgv|2l95<45l-bhs3%9TIC zji10@@s(3i1C4Seh@Q0P7;K_bHQVNmjWN&F4#OV^2TkW2pua=Y!#x z3lYuIVHB$r7|21K%oHS?GtjLVSftoqQNHE`n1V4|++Ed5=k$M_T9k2i_t$P3?N zLDkek&A7k?+dvmq?V(^FipG6KaA;%eeqOe(6T#Y}RH|r^h%rPn8nwHSOqfb!hWz4u za2~}|HluCHV8LK-o^}dcKAV5gk2X8{#}=eTA+6GUat}kp1UFCi`",methods=["GET","PUT","DELETE"]) +def retrieve_update_delete_FilmManufacturers(filmmanufacturer_id): + if request.method == 'GET' : return retrieve_filmmanufacturer_controller(filmmanufacturer_id) + if request.method == 'PUT' : return update_filmmanufacturer_controller(filmmanufacturer_id) + if request.method == "DELETE": return delete_filmmanufacturer_controller(filmmanufacturer_id) \ No newline at end of file diff --git a/server/__init__.py b/server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/__pycache__/__init__.cpython-310.pyc b/server/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aa7c5ed62a020ea14a47245af3727f73df55de6a GIT binary patch literal 156 zcmd1j<>g`kf^Q2%(?IlN5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!H$enx(7s(yND zaYZ;w22&_M6dy`)sLjFMG z-Q|Mu6^Q;F6epZY662RiTCkW=#Ex_dH+F06O0V!^zs8;niZBiV`#g}1q7gSJ5$*+v zBjJN?@{l*4lei^Xf~?y-+RzIccSL8s!ZtM_$=tvCDT( znfg(5W>Jtm(Mee-9y5%&)u zE2wPXj~+vYJ4%#Xs3g_NI5pXc4It%GWF}*f+S`RWqa1_i4?(TSnrz59Td_6eb&i18 z2JYtIG+?7=dyl@~e{i^eeNrirPs`*~oarx*MqdmZU}d3nrEDOcifmzo^)gv$0e`xD zoX+#)O$vEc+TJBjl*lT@6^`9+MD4)m)ve)4Rfyqqp-sB1id>~7Plu0GH4~=N!-HHF z_wOcm)9e(=9BQGKLJiaT{Kovu_OvjG{z>LWBy*Kci}Wg%=YtAaL|gRPXPFYv)&v7? z%PLEyzH{S0QG=#Ju56ejWmdE8qa`C%lO!ad6^r$%Lc`EUThOAtk#I9 zMtOCV%(W4vPJlP-i*lNmNK6x)V33lc;=(!*rF!69bFfui42~}IZG)|^feLAtMhv9| zB}K2@M)xnbp*}$W=DnlQ!8Z?*!=w9OzoNqo&i=7*Z0j+_w~WsL8f$}xLQ3odHsIf? zPQyDvk5AyYMq*s1uEPh0&0Q#|k*6Zf%OrW6Kl}*Jnf16BFQ(R=SIP|bEUUEjCiv2} z#CB_ptxC5~PT?%t_V)M*Bnq zkMX#R@GvbGlQc66C6wypv7;8H_2w!s&Ht7j-i8h>q_~6B=}$q01bMGF^BtdttkVx2 N7%!)VnD(jr`frb0QJeq( literal 0 HcmV?d00001 diff --git a/server/__pycache__/config.cpython-310.pyc b/server/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..806375ba201c122f491282121bcf6d9b9220190d GIT binary patch literal 1258 zcma)6OK;Oa5Z+xowwp&up;Ze=z2`#y0H8RJhKMvNjf;dYmX+OxKx~(_6A7;6XK*Oo z`j_^~0dejHAr8!JO6$HPHrmO4yQBGLzMXYasT2u}AKx|(e=$P7Bgl^efCkL;6Btf7 zoe>}Z*^EZaXOswbOepCRZgBH6;pQ>(4L}8M0kVW~Z1^T%n>&CVjSGNRcoA?>V+(MJ zmjRbGwuLDQ!V)&Gd@+58(-Eny{sew9s8Lm#B_R)Zl8JaR#?Abo02(mUDi}e0%8Ac7 z^$pG-h@q@j5+6<{-k@eGCkWy&5<#GfK@cT;KEri62tLfi+4;%#=vCkCw_bF1-vr*i z+j<%74%@w*Ud#1*!@=m3NC$|t`TeZ^Hi<-iGEcK`kwjA&#yqU=$>g2LlC-`voki_t z&x)L2Ik4)sdC8d?B|fq@1VAXZswVeTuE(kTSK{Dyte*6DKP$iofEYzhmVB AjsO4v literal 0 HcmV?d00001 diff --git a/server/app.py b/server/app.py new file mode 100644 index 0000000..17ad3c2 --- /dev/null +++ b/server/app.py @@ -0,0 +1,43 @@ +import os +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_migrate import Migrate +from sqlalchemy import event + +from .config import config + + +db = SQLAlchemy() +migrate = Migrate() + +def create_app(config_mode): + app = Flask(__name__) + app.config.from_object(config[config_mode]) + + db.init_app(app) + migrate.init_app(app,db,render_as_batch=True) + + with app.app_context(): + @event.listens_for(db.engine, 'connect') + def set_sqlite_pragma(dbapi_connection, connection_record): + cursor = dbapi_connection.cursor() + cursor.execute("PRAGMA foreign_keys=ON;") + cursor.close() + + + + return app + +app = create_app(os.getenv("CONFIG_MODE")) + + +@app.route('/') +def hello(): + return "Hellord" + +from .Film import urls +from .FilmManufacturer import urls + +if __name__ == "__main__": + app.run(debug=True,port=8008) + print(os.getenv("CONFIG_MODE")) diff --git a/server/config.py b/server/config.py new file mode 100644 index 0000000..7d0ad73 --- /dev/null +++ b/server/config.py @@ -0,0 +1,29 @@ +import os +from dotenv import load_dotenv + +load_dotenv() + +class Config: + SQLALCHEMY_TRACK_MODIFICATIONS = True + +class DevelopmentConfig(Config): + DEVELOPMENT =True + DEBUG = True + SQLALCHEMY_DATABASE_URI = os.getenv("DEVELOPMENT_DATABASE_URL") +class TestingConfig(Config): + TESTING = True + SQLALCHEMY_DATABASE_URI = os.getenv("TEST_DATABASE_URL") +class StagingConfig(Config): + DEVELOPMENT = True + DEBUG = True + SQLALCHEMY_DATABASE_URI = os.getenv("STAGING_DATABASE_URL") +class ProductionConfig(Config): + DEBUG = False + SQLALCHEMY_DATABASE_URI = os.getenv("PRODUCTION_DATABASE_URL") + +config = { + "development": DevelopmentConfig, + "testing": TestingConfig, + "staging": StagingConfig, + "production": ProductionConfig +} \ No newline at end of file diff --git a/server/migrations/README b/server/migrations/README new file mode 100644 index 0000000..0e04844 --- /dev/null +++ b/server/migrations/README @@ -0,0 +1 @@ +Single-database configuration for Flask. diff --git a/server/migrations/__pycache__/env.cpython-310.pyc b/server/migrations/__pycache__/env.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3ef75d8fe08c4ef3a8418eb71bb7744baf81ad3b GIT binary patch literal 2824 zcmaJ@QI8w95hl5--PN9?lP@_Vu90Nx)^G&0x)x}QqA-Hy92*Fl9s-}+AosH1Eh%Z` z)viiXce#V^N$Eo$(*A)yNI+it2l`|9+Nb`67;W4cuB1E1MkSC-a)-m=H{Z-`)o#ZG zeuL!ppxY+oUpTq>^I`H^X!;xI1QE0#C-`Iqov;%|aqJb|#6R)f*e@EB;3S|#2IKG~ zluU->XhC64mQB%E(UVvNBK(S+?1)G-;n|YmvMplST96g!lm56PcJ7ez?nzg)L>nY- ziH_KX=bq?_Tkw2K2FtfsMEzdwEeM=SkBNM1GwSXA8!RP9J!<1YUdTsPImm}F+sS51 z$DjUPmvebE1YRkl_jfc{tvK;26 zw9RK1Q~6k_O4-gw#;E*sX4dnd7WoHJEzsh+7mp7{)kGc)XWHae( z`rt`kOg=tL4|(=nmf}E5btct8Z4MrP0Qc@sFH{5y_n>Jc1fzSb3ypo})?dQ~g&i)3 zFt}_RvH)bpOi;nTrb|zF!e6lsJ{QRvn?^0S*h*{>Y8*WQpR`B0km;0beO@W?g5JMm z_wV-tXM*)+s<2(~ppYu%I@JJ7IkcgY(}HJGq1o1h)oW<#5zw00&NaR%D7p)4x&s}f zUFy@|WsAK-*-P~{EWPOHKNY;lMsjk|2U*pC#n%u(FFFK%00Tn|@M6JKY!C%<2mB5r z@7VdiIgy47Zn*CGHXL!y!Kt=sxI&}Esk#j+Y_ySjqx~%u-AMcl_NG6q#{WwnG_iU8w1R@SXai*kB z%t+!C128$y%_tcIdlR1g;pwMN9w?lY6|9uWV;2-Zfi2Z+IJ#a*KqJpGIW_#WkZ#vV zDw%MdoXeuf3-2cFTa!-#ODXS#2qguxpAirbJSR~6y@Q{?nIrbd}@+v zW~MWFN6&hm>cZ3Ru9>lMw`~`>k%|}TXM=M<#y(-t=Xo~f5HS4#8(7Zh>6t0M0!Q%m=63E6^$8D`*Sjn$<_3RfbNUVaD{#^T%OzQJseuo_covk=iRBQGO2aC*_2-I`6D8N8NLGyjcJQ^sQ(|IUH<0#ly*++KP;+@7y85g z|551*f%+-vJnAtUU%N_SIdR7Ic3gQ^n4E2A8-^*QdTl+xr>K{WF?X*I~B49BKD1)l!f5*Jw zzi|-L_g;3sW#PSV)h|G>w{Jsq4OZ9AdeE=0q8PlljX}Zn^ZGj`Tz@^)H*t>d*0L#n zeWfLzzy}Rn{8Q&_^#Lew7`RevcQux^8~F=?Qz3TmVCPW5wBjtYyFi|G4ob1Q+ZLt;$d`wi47d1Pr7LB4Pi1wo&K@nyD19|w*4*&oF literal 0 HcmV?d00001 diff --git a/server/migrations/alembic.ini b/server/migrations/alembic.ini new file mode 100644 index 0000000..ec9d45c --- /dev/null +++ b/server/migrations/alembic.ini @@ -0,0 +1,50 @@ +# A generic, single database configuration. + +[alembic] +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic,flask_migrate + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[logger_flask_migrate] +level = INFO +handlers = +qualname = flask_migrate + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/server/migrations/env.py b/server/migrations/env.py new file mode 100644 index 0000000..4c97092 --- /dev/null +++ b/server/migrations/env.py @@ -0,0 +1,113 @@ +import logging +from logging.config import fileConfig + +from flask import current_app + +from alembic import context + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +fileConfig(config.config_file_name) +logger = logging.getLogger('alembic.env') + + +def get_engine(): + try: + # this works with Flask-SQLAlchemy<3 and Alchemical + return current_app.extensions['migrate'].db.get_engine() + except (TypeError, AttributeError): + # this works with Flask-SQLAlchemy>=3 + return current_app.extensions['migrate'].db.engine + + +def get_engine_url(): + try: + return get_engine().url.render_as_string(hide_password=False).replace( + '%', '%%') + except AttributeError: + return str(get_engine().url).replace('%', '%%') + + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +config.set_main_option('sqlalchemy.url', get_engine_url()) +target_db = current_app.extensions['migrate'].db + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def get_metadata(): + if hasattr(target_db, 'metadatas'): + return target_db.metadatas[None] + return target_db.metadata + + +def run_migrations_offline(): + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, target_metadata=get_metadata(), literal_binds=True + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + # this callback is used to prevent an auto-migration from being generated + # when there are no changes to the schema + # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html + def process_revision_directives(context, revision, directives): + if getattr(config.cmd_opts, 'autogenerate', False): + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + logger.info('No changes in schema detected.') + + conf_args = current_app.extensions['migrate'].configure_args + if conf_args.get("process_revision_directives") is None: + conf_args["process_revision_directives"] = process_revision_directives + + connectable = get_engine() + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=get_metadata(), + **conf_args + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/server/migrations/script.py.mako b/server/migrations/script.py.mako new file mode 100644 index 0000000..2c01563 --- /dev/null +++ b/server/migrations/script.py.mako @@ -0,0 +1,24 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade(): + ${upgrades if upgrades else "pass"} + + +def downgrade(): + ${downgrades if downgrades else "pass"} diff --git a/server/migrations/versions/724351b0562f_.py b/server/migrations/versions/724351b0562f_.py new file mode 100644 index 0000000..efc52c9 --- /dev/null +++ b/server/migrations/versions/724351b0562f_.py @@ -0,0 +1,44 @@ +"""empty message + +Revision ID: 724351b0562f +Revises: +Create Date: 2024-04-10 02:15:27.572875 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '724351b0562f' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('film_manufacturer', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('name', sa.String(length=255), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('id') + ) + op.create_table('film', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('name', sa.String(length=255), nullable=True), + sa.Column('ISO', sa.String(length=10), nullable=True), + sa.Column('Push_Pull', sa.String(length=10), nullable=True), + sa.Column('fk_FilmManufacturer_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['fk_FilmManufacturer_id'], ['film_manufacturer.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('film') + op.drop_table('film_manufacturer') + # ### end Alembic commands ### diff --git a/server/migrations/versions/__pycache__/724351b0562f_.cpython-310.pyc b/server/migrations/versions/__pycache__/724351b0562f_.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..33eb7af6291942d74b1631d19cab7efbc4f50677 GIT binary patch literal 1195 zcmb7DL2uJA6poWLNwaorqfCG}Ns1%1+>S1;rT+c0hE3RbY`xrU`~D^1GwMj0e7vtJ^U((SWPVgZ>B5rVL1e}SA}BMDEMjKng*`Qh zMQlEU6+tjKIiteh@S@{}oek7YChyv|`JViu{|frwKqCU5AZ z%bCmsjsf=4M;4#tbk0)S<$}f$yW#iE5Dy_=A%1;ojCe{LQ7$ul%F|e2MsVXm@FSXW z+0aGoY=_%;a7-C#NGeXLXryr@a0XnJ4Nx^{Wn-RW;o5kj+!A7z=u8%rkmU(G|&na97W3?TZCC7dD8xIqRoS1Ru}3 zd0p^q_XylnneZ>HfcO+tsjvFxA`(w@j0NR}A>o5CR4z_v+K&fUQRPX3lfj6l6S1tr zc;f2ERaG4@yjJ_r%)uxGCecJHpU^S%P==fpl@@vK1m4K} J^z^LCgTG%xH-!KI literal 0 HcmV?d00001