Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
In this session we'll have a brief look at the settings.py file and do a migration for the saturn project.

To setup your database you need to give the credential in saturn/settings.py in the section:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


As you see above the default database is set to sqlite3 and the NAME of the database is set to file path of db.sqlite3, if your database is set to MySQL you would have to provide the name of the database in NAME section.

ENGINE can have one of the below database bindings:

'django.db.backends.sqlite3',
'django.db.backends.postgresql',
'django.db.backends.mysql',
'django.db.backends.oracle'


If you are using a db other than sqlite like MySQL you should provide USER, PASSWORD HOST beside ENGINE and NAME.

INSTALLED_APPS is a section that contains apps used by
our project. For example for session management there is django.contrib.sessions section.

Some of these applications use database tables, so for Django apps to work properly, youn need to use migrate command
and create corresponding tables:

$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying sessions.0001_initial... OK


You can see that needed tables are created as above. In case you don't need an app just comment it out from INSTALLED_APPS before running migration.

The next session we would create models for our tables and would do the real parts. :)

#python #django #settings #INSTALLED_APPS #migration #database #ENGINE #django_part4
Metabase by default uses H2 Database for its internal usage and storing questions and dashboards that you are created. When you want to move from one host to another it can be tricky and it may crash! Here you will lose your dashbaords and your containers. This matter
gets important when you have loads of data there (let's say hundreds of questions and tens of dashboards).

The safest way for production is to migrate this data to MySQL. It makes Metabase to use MySQL as its backend not H2 Database. To migrate your data from current working H2 DB of Metabase you need to set following variables first:

export MB_DB_TYPE=mysql
export MB_DB_DBNAME=metabase
export MB_DB_PORT=3306
export MB_DB_USER=<username>
export MB_DB_PASS=<password>
export MB_DB_HOST=localhost
java -jar metabase.jar load-from-h2

The last command will run metabase and forces it to migrate data to MySQL. In case needed create metabase database in mySQL with sufficient privileges. It should come up safely with no much headache. After moving data remove you *.db metabase h2 DB file.

#metabase #migration #H2 #mysql