How to delete the ContentType and related db tables in Strapi? - strapi

I am using Strapi v3.0.0-beta.18.7
How to delete the ContentType and the related tables from DB ?
I tried the command below, but it is not deleting the db tables.
DELETE http://localhost:1337/content-type-builder/content-types/application::CONTENT_TYPE_NAME.CONTENT_TYPE_NAME

To delete the content-type and related db-tables in Strapi,
You can delete the folder inside /api folder having same name as your content-type
Suppose if you want to delete the "product" content type, you can delete the product folder inside of /api

The database's tables sync is not managed in the Content Type Builder plugin.
By default, Strapi doesn't delete anything from your database structure.
Strapi is customizable but you will not be able to update this.
Here is an issue that talks about this topic - https://github.com/strapi/strapi/issues/1114

The answers above are really helpful but don't explain, how you would actually go about deleting the table manually.
Suppose you run a local default installation with sqlite, you can find your database at .tmp/data.db. To connect to it, you will need a tool that you can get from sqlite directly:
https://sqlite.org/download.html
I guess you can add it to the PATH, but since I am a beginner and I just wanted it to work, i put the sqlite3.exe directly in the folder of the database and ran it.
To open the database, I used .open data.db and tested it with .tables which showed me all the tables that strapi created for me but didn't delete.
To ensure that I found the right table (recipe-cuisine) i looked at the content using .headers on followed by SELECT * FROM "recipe-cuisine";.
I finally deleted the whole table using DROP TABLE "recipe-cuisine";.
There is an awesome documentation on how to do other operations here: https://www.sqlitetutorial.net/
I hope that helps other beginners who struggle to delete the tables. If anybody has suggestions or helpful links with more information, that would be great!

Lets assume you need remove abc collection.
WARNING
Be sure you created backup and there are not other collections that contains abc substring.
Then you need execute commands:
DELETE FROM `users-permissions_permission` WHERE `controller` LIKE '%abc%';
DELETE FROM strapi_permission WHERE `subject` LIKE '%abc%';
DELETE FROM core_store WHERE `key` LIKE '%abc%';
DELETE FROM upload_file_morph WHERE related_type LIKE '%abc%';
DROP TABLE abc;
Then you need execute also:
rm -rf api/abc
Additional notes:
take care about plural names
be sure that there are no relations with other tables in other case you will see error
TypeError: Cannot read property 'globalId' of undefined

Related

How to delete jDateChooser from database

I have a problem when I want to delete the data in JDateChoose from database(Localhost) and the table.
When I want to delete it, the message said it's success but from the table and the database there still a data.
In youtube, I don't find the right solution to my problem. But when I use this syntax :
DC_TanggalKupon.setCalendar(null);
The field is deleted from the JDatePicker but not the table and database

Rename a Parse Platform class

Does anyone in the Parse Platform community know if it's possible to rename a Parse class? E.g. I've got a class called Products and I'd like to rename it to Product.
Is this possible or do I need to do a full migration of all the data?
I found this github issue which was super helpful and lead me to the answer: https://github.com/parse-community/parse-server/issues/617
All I had to do was:
Rename the collection in the db (db.Products.renameCollection('Product')
Find the schema (db.getCollection("_SCHEMA").findOne({_id: "Products"})) and make a copy, update the _id and insert it.
Write a quick script to update all pointers in my Product records to point to className of "Product" rather than "Products".
Remove the old Products schema
Everything seems to be working as expected.

Joomla: regenerate aliases for all articles at once?

I am working on a Joomla 3.2.1 site and the client, without thinking, entered in the same alias for all articles, instead of letting the system use the article title. So now if I want to turn on SEF URL's we are going to have 404 issues in the future.
I want to resave or regenerate all article aliases at once (batch).
Is there a way to do it? in the MYSQL DB maybe?
Thank you in advance.
$alias = JApplication::stringURLSafe($article->title);
Joomla will generate the alias when saving the article. I am not aware of any batch joomla feature to regenerate all the aliases and I would also be interested to know about this.
If no other batch solution exists, you should do manually the updates to these fields.
In the database, you could run update queries for all your articles, but you must type each update query one by one.
The update query for a single row would look like:
UPDATE jos_content
SET alias='my-new-alias-name'
WHERE id='{id-of-the-article}'
For multiple rows at once, you could do something like this:
UPDATE jos_content
SET alias = CASE id
WHEN 1 THEN 'alias1'
WHEN 2 THEN 'alias2'
WHEN 3 THEN 'alias3'
END
WHERE id IN (1,2,3)
What you could do is delete the alias data from all of your articles in the database using mysql. Then make a tag, like "fixalias." Using the batch processing feature tag all of the articles with that tag.
This will run store() for all of your articles and automatically generate the aliases. Then delete the tag from the tag manager.you ar
A similar strategy would involve also deleting all the aliases but batch moving (don't copy) your articles to a temporary category and then moving them back.

Saving copy of old table entry to another table when updating table entry with SaveChanges()?

Im working on an online store project where I have already made it possible for an administrator to update different table entries via the store gui (like items, user profiles, orders etc). SaveChanges(); is used to save the changes.
Im currently trying to figure out how to make this work:
An entry in table "items" gets updated.
Before the entry in the table "items" gets updated, a copy of the old entry gets saved into a table named "history-items".
The copy that is saved to "history-items" preferably has a timestamp.
How would I go about doing this? (As you might tell, I just recently picked up visual studio, and am pretty new to everything)
Thank you.
There are atleast 3 ways to do this:
If you are using SQL Server 2008 or newer this is now built in functionality, see: http://msdn.microsoft.com/en-us/library/bb933994.aspx
If you opt not to use that then the simplest solution is to use database triggers.
If you want to do it in C# code, then you need to read the original values before saving, and save these original values to the history table. For reading original values see: How to get original values of an entity in Entity Framework?
I would go for option 1 if possible.

Dynamic table names in Doctrine

If I have tables in doctrine for user_1, user_2, etc. is there a way to dynamically set the table name in Doctrine for a single User model?
It's weird, I know. I'm trying to create an interface to a WordPress database (because WP has little to no API for directly accessing posts), and WP creates duplicate tables for each site, so there's a wp_posts, wp_comments, wp_2_posts, wp_2_comments, etc.
Here's what I ended up doing:
$post = new WordPressPost();
$post->setTableName('wp_'.$user_id.'_posts');
If it could, you would have to run migrations for each added/deleted user.
I am curious; why would you EVER need something like that?
I don't know how WP works, but here is the thing; each site should use it's OWN database, not to share it with others.

Resources