how to migrate document oriented db to mysql - mysql

I can find all over the web articles to migrate an existing MySQL database to a SimpleDB or CouchDB or what so ever.
But If I go ahead and migrate my millions of records to Riak or CouchDB, is there any way to migrate back?
Would it be possible in theory to regenerate all the relations between my data that has no clear indexes to a relational database and regenerate all the relations?
Example:
I have two tables in MySQL one is person and one is job, job is related to person - in one to one relationship.
If I switch that to couchDB, person document will have the job defined as text value for the key "job"
inserting this relation in couchDB is very simple from MySQL. Select.. combine then dump one person object.
Now, split one person object into two objects - and find the correct key for the certain job. How?
Any help is appreciated!

Here's my idea:
For the example, I'd start with looping through all records to create a list of jobs, then adding those to the jobs table. Then do a loop again, this time matching the 'job' in persons to the newly created job in mysql and fetching the id, adding that id in the person table 'jobid' foreign key field.
This way of analysing the data could probably be generalised in a script, but you would need to present it a 'translation' array or something, defining the relations.
To answer your question, yes, in theory it should be possible.

Related

Same table in multple schemas

New to this, I am creating a database for an application. As the schema is becoming visually complex very rapidly, is it possible/feasable/recommended to have the same user_table in multiple schema?
For example, the blogging schema would have the user_table and the rest of the tables related to this activity. The shopping schema would again have the same user_table and the tables to manage the shopping activity. And so forth....
The objective would be to separata the plenty of tables in different schemas so to simplify the overall managements.
In another post, someone suggested creating a synonym in one the of schemas, referencing the other schema table. Is it the way to go or am I totally misrepresenting problem and solution?
Thank you for your time reading this.
A user table serves two diffent features, each in its own schema:
Sharing tables between schemas is not directly possible. There's a feature called federated tables, which however is not enabled by default and must be enabled at compile time of a MySQL server. So, it's rather not available for your task.
Instead you have only two options:
Use a single schema to avoid data duplication.
Use multiple schemas and maintain tables like the user table in each of them in parallel (by executing the same update queries on each of them).

Normalization - How do I properly reference a list from one table in multiple fields in another table?

I'm pretty sure this is a basic question, but I'll be darned if I can find an example that helps me understand the proper way to do what I need to do.
In MS Access 365 I am creating a maintenance tracking database. I have a table with basic employee information. Employees can both perform maintenance tasks and verify maintenance tasks. I can set up a one to many reference using the Employee ID PK as a FK in my task log table for who performed the task. Obviously, I can't set up another one to many relationship to a field of who verified the task.
I already have the task details in a separate table which is referenced by the task log table. Am I just being stubborn in not splitting my task log table into task performed and task verified? Is there another way to normalize this data?
Obviously, I can't set up another one to many relationship to a field of who verified the task.
Yes, you totally can.
When you drag&drop the 2nd relation, Access will ask if you want to edit the existing relation or create a new one.
It will display like this, but it is actually 2 one-to-many relations from User to Log.

Does IntelliJ has a function to visualize the relationship between two specific tables in a database?

I'm working with a big mySQL database in IntelliJ.
I'm trying to join two tables which aren't in a direct key-relation to each other. Hence I have to join over multiple tables.
Because I barley know the database scheme, I can't find out these tables in a appropriate time. I know that IntelliJ has a function which can visualize all tables with their relations within the database but does it also provide a function where I can find out all tables in between two specific tables?
You can get help from Intellij partially for your task, using the visualization feature as follows-
The relationship between tables are clearly shown.
For your question, you need to check the primary and foreign keys for each table which are easy to know as they are highlighted.
Traversing them you can find the relationship.

How do i build a relationship between database and a database?

I have a bunch of zip codes. Each zip code has its own database. The tables in each database are only related to that particular zip code. I also have a customer database. Each customer can only be assigned to one zip code. Being assigned to a zip code, that customer has access to all the features/TABLES of that particular zip code.
If I had all the zip codes and customers in one database I could easily join the tables using Foreign Keys / Primary Keys. But I feel it is more organized to keep each zip code separate as its own database. I choose it this way because each zip code is completely unique from one another.
I am new and have been watching tutorials but I only see table to table solutions. I would like to know how can I build a relationship between databases.
To answer your question: there is no way to establish relation between data in different databases.
Your design doesn't make things more organized; on the contrary, by creating multiple databases with similar - and related - data, you make it much more difficult to establish connections and to work with the data in an effective way.
Consider moving all data into one database, and adding "zip_code" field to tables so you can easily select data from each zip code as needed.
A "database" in MySQL is just a schema
You can query between and have foreign keys between schemas, just use the fully qualified name schema_name.table_name
I can't see a good reason to have zip codes spread among schemas. They should all be in the same table with a "country" column.

How to synchronise Core Data relationships?

I'm creating an app that pulls data from a web server (MySQL), parses it and stores it in a SQLite database using Core Data.
The MySQL database has a 'words' table. Each word can be in a 'category'. So the words table has a field for 'category_id' to join the tables.
I'm having some trouble getting my head around how to replicate this locally in my app. I currently have entities matching the structure of the MySQL database, but no relationships. It seems like in my 'words' entity I shouldn't need the 'category_id' field (I should instead have a one-to-one 'category' relation set-up).
I'm confused as to how to keep this Core Data relationship in sync with the web server?
Assuming you have an Entity for Word and Category you will need to make a relationship (naming may be a bit hazy). Also assuming a Category can have many words and
// Word Entity
Relationship Destination Inverse
category Categories words
// Category Entity
Relationship Destination Inverse
words Word category // To-Many relationship
You are correct you would not need the category_id field as all relationships are managed through the object graph that Core Data maintains. You will still need a primary key like server_id (or similar) in each entity or you will have trouble updating/finding already saved objects.
This is how I deal with syncing data from an external database (I use RESTful interfaces with JSON but that does not really matter)
Grab the feed sorted by server_id
Get the primary keys (server_id) of all the objects in the feed
Perform a fetch using the a predicate like ... #"(serverId IN %#)", primaryKeys
which is sorted by the primary key.
Step through each array. If the fetch result has my record then I update it. If it does not then I insert a new one.
You would need to do this for both Word and Category
Next fetch all objects that form part of a relationship
Use the appropriate methods generated by core data for adding objects. e.g. something like `[myArticle addWords:[NSSet setWithObjects:word1, word2, word3, nil];
It's hard for me to test but this should give you a starting point?
Good to see a fellow Shiny course attendee using stack overflow - it's not just me