how to add django-database-size to django project view? - mysql

I am trying to use django-database-size to display mysql table sizes to django admin page. The project has very limited docs to how to add the view.
Here is the repo: https://github.com/chrisspen/django-database-size
All it mentions about adding the view: Install the appropriate view in /sql (currently only PostgreSQL and MySQL supported).

App name = database_size and you need to create the view based on files in database directory.

Related

Using same database table with two different projects Django

I'm a beginner in Django.
I would like to know how to configure two different projects to share the same database table in Django. The database I'm using is MySQL.
Let's say there's two projects, project A and project B. In project A, I already created a custom user model in it. And in project B, I want to use the custom user table from database created in project A just for the login. Means that in project A, there's registration and login for the custom user model.
In project B, there's login only that will be using the same custom user data in the database.
Do I have to redefine the same custom user model from project A in project B?
What are the configuration settings that need to be done?
Thanks in advance.
project B can't accessible table from project A. but same database can accessible to multiple projects via enabling remote access on parent project database. but you should keep some point whenever your are made a model in any project then you must add that model in remain project
Okay, somehow I managed to solve this.
Like the previous step, I did python manage.py inspectdb > models.py in project A which I already created custom user model that used for registration and login. Then, I copy that models.py file into project B and changed the custom user model generated by project A to the exact same steps when I created the custom user model in project A. Means that I did the CustomUserManager class as well as the other necessary things required when you create a custom user model(AbstractBaseUser).
Then, in the settings.py of project B, I did AUTH_USER_MODEL which somehow solve this issue.
It seems like in order to use the same custom user model in different projects with same database, we need to redefine the exact custom user model along with managed = False.

Replace the URL of all my rev sliders inside images to work with new domain

I have migrated my website to a new URL and I'm wondering if there's a way to replace all the instances of the old URL with the new one using MySQL.
The images show in the Media tab but aren't linked to the slides.
Is there a way to achieve that?
If you did migrate by editing Settings → General, Site URL and Wordpress URL, it might be that some plugin stored the full URL instead of the media attachment ID. In this case, you can use the WP Cli ( https://wp-cli.org/ ) to do a search-replace on the entire database. Use it like so:
wp search-replace 'http://old.url' 'http://new.url' --path /your/wordpress/directory/
on the command line of your choice (replace "wp" with the executable of your wp-cli).
Just to be on the safe side: do a backup before:
wp db export --add-drop-table
This will generate an SQL file you can use to restore your database in case anything breaks replacing the URLs.

yii2 customized CRUD under version control

Is there some possibility to write customized CRUD not in vendor directory as I want put it under git version control. I tried like here https://github.com/yiisoft/yii2-gii/blob/master/docs/guide/topics-creating-your-own-templates.md. I can't find link to CRUD under gii-generators.

How to access an internal database in Bolt?

I have a custom contenttype called posts, which has about ten records. Each of them is stored in bolt_posts table together with other Bolt-specific tables. I'd like to access a post with id = 1 in one of my custom php files. The problem is that the database for my application is separated from the database which holds internal Bolt tables. Is there a native Bolt API that I could use in order to query those tables? I've found this https://docs.bolt.cm/3.1/extensions/storage/queries, but I am not sure what directives I need to put in my php code in order to be able to run such commands. Thanks in advance!
Assuming you're using composer to load Bolt into an existing application then this can be achieved by constructing an instance of a Bolt app.
All you need is a configuration, that takes the root folder of the Bolt site and then to initialize the app. For instance, assuming Bolt is accessible via autoload..
$config = new Bolt\Configuration\Composer('/path/to/bolt/root/');
$app = new Bolt\Application(['resources' => $config]);
$app->initialize();
That gets you the instance of a Bolt app and then you can follow the instructions in that documentation to query the Bolt db.
eg:
$record = $app['query']->getContent('pages/1');
if you want to access the content from within an external application, you need to connect to the bolt database manually and fetch the data. Bolt's own storage layer can only be used when you work directly in Bolt (e.g. within an extension).

Can't access MySQL views when moving the PHP application on another server

My current project is about doing some changes in an already build web application (PHP/MySQL). For displaying data, the previous developer used views. I got the app on my computer in order to get familiar with it and I can't seem to make those views work (I don't get any output in the app).
I searched the web for this an there seems to be a problem when you create a view with one database user and the that user no longer exists.
Anyone who got into this issue before? How can this be solved?
If you're importing the views from SQL dump file, they are probably defined like this
CREATE DEFINER = 'userWhoDoesNotExist#thisServer' VIEW viewName AS ....
Try removing the DEFINER = part, and the view will be created using currenct user account.
since you are running the server on your own computer, I am assuming you have root access. Try using something like
ALTER VIEW brokenView DEFINER='newuser'
this passes the validation check here. As long as you are root when you do this, you should be able to recover your views.