I am currently using Flask and SQLAlchemy to create a web application.
However, I am in the process of creating a User model with passwords and usernames. Do I need to find my own libraries to salt and hash the passwords or does SQLAlchemy or Flask provide this in some way?
Also, what is the most popularly used with Flask and SQLAlchemy for database migrations?
Lets assume that I change my model. How do I drop the old schema and tell SQLAlchemy to use the newer one?
Yes, there are libraries out there that should handle this for you. How much work they do is up to you. Some, like bcrypt or passlib, will just give you the algorithms needed to generate the password hash. Others, like Flask-Security, go one step more than allow you to use mixins to handle even more.
As for database migrations, check out alembic. It's a migrations utility built by the lead maintainer of SQLAlchemy.
You have another question in there about a "particular way that Flask developers prefer to drop the schema". I'm not sure what this means, but I would imagine that if you went into a bit more detail, you could probably ask it as a separate question. Just keep in mind that any question that asks why something is preferred should be asked cautiously: preferences are subjective, and therefore, asking questions on why something is preferred would also likely be subjective.
Related
Is just a question about laravel seeding, if I want to make my app portable, it is a good practice to save app-work-essential data in DatabaseSeeder laravel class?
If not? How could I do it?
Seeding is used to bootstrap the application. If the data is just enough to get the application up, seeding is the official way to do this; especially if you are in an environment using Continuous Integration/Deployment. The paradigm is that you, as developer, shouldn't have to have direct access to the database to install or update the application. I don't necessarily believe that needs to be true, but it is a nice ideal to shoot for, as it means the code will be more portable.
One very important exception is based on the idea that the seeder is typically versioned, so it shouldn't contain sensitive or private information. Things like real user password hashes (a temporary admin password is alright), HIPAA, FERPA, social security numbers, bank account information, etc. etc.
I recently started working on a long-running MySQL-backed Django website. The code is mostly clean and well-written except for one patch in the database that seems to have been hurriedly applied.
Specifically, one of the Models was named tbl_Badge_data. As per the naming conventions applied to the rest of the website, this Model should be named Badge.
Unfortunately, there has already been too much built upon the wrong name, and it is infeasible to change the existing scripts (these include Django queryset operations as well as SQL statements). Replacing all instances of the wrong name is not possible, as not all code is owned by us; there are other users relying on this data.
Is there any way to alias Badge to tbl_Badge_data so that all future development uses the correct name? If yes, how will this impact the name of the underlying table? If not, what is the best way to handle something like this without introducing a performance hit (e.g. a "proxy table" or "proxy model" which is a one-to-one map)? As you can imagine, my team doesn't want to invest time in this non-issue (and probably justifiably) want me to ignore this.
A proxy model is not a one-to-one map; it has no representation in the database, and does exactly what you want.
Even simpler though is just to define an alias in your models; after the definition of tbl_Badge_data, you can just do:
Badge = tbl_Badge_data
and import Badge wherever you need it.
Reading some new functions on the mysql development documentation page, I come across what looks to be a gimmick and in my eyes provide no practical usage. The function in question is
show create table tablename
which outputs how the table is actually constructed.. So the question is, how would this be useful in an actual productio mode? a function which shows how the table is created?
Possible scenarios:
Assist in automation of deployments for some PHP packages which rely on a database? Just stick to importing a .sql document on running the installation?
Create a new table on the fly via php? That's somewhat-bad practice imho
understandably this can be boiled down to the common response with asking exec() questions within PHP or other languages.
if exec is your answer, you are asking the wrong questions
So the overall question, which might boil down to the above quote, is what practical usages will this show create table actually perform in a production state SQL Server?
as most production servers import a .sql document when an updated package is released, this minimizing possible conflicts from manually importing and not configuring a datatable correctly on the production server?
show create table is a convenient way to see column types, constraints, etc. It's helpful when trying to answer questions like "which fields on this table are indexed?" for example.
I hope this is not an obvious question. However, I cant find any resources online, since everytime i google wordpress with pyqt, i get websites made with wordpress talking about pyqt.
Are there are resources or tutorials on integrating pyqt with wordpress. Or is this too vague, and it should be pyqt with mysql? Or is this just a bad way to write a program in python that gets data from a mysql database?
My understanding what you're looking for here is not to integrate PyQt with WordPress, but rather Python itself. PyQt it simply a toolkit that offers the GUI (and many more) module that you're likely using, but Python is still the "backbone" of your application.
In order to manipulate the database that WordPress uses, you'd have to manipulate that very database. For that, I recommend MySQLdb Python module. Alternatively, you could use the QtSql that PyQt comes with, but I honestly don't see the need for that.
However, I have to advise you that altering the database directly could have unwanted consequences and it could potentially break your WordPress installation - so make sure to backup the database often. Also, this poses a certain security risk. If I were you, I'd create a WordPress API (there may already be one, I'm not that familiar with WordPress) that will take HTTP requests and send responses as well, which your Python program would then use.
The question is pretty simple, however it seems like there's a million variations on the answer, therefore although this question has definitely been asked before, I'd like to ask it again in the hope that an up-to-date answer can be sought.
Basically I'm creating a Mac app and part of it will be powered by data that I have in a remote MySQL database as part of my site. My question is this: what is the best way of connecting to that database so that the data can be used in my app?
I have read many answers that suggest using a web service to convert the database to JSON or equivalent and then converting that into objects that can be used via Core Data is the best way, however the data that I want is 'dumb', i.e. I won't be changing or manipulating it in anyway, therefore I think Core Data is potentially overkill for what I need.
Are there any other more straightforward ways of achieving this task?