E
E
Eugene2019-07-31 20:14:54
MySQL
Eugene, 2019-07-31 20:14:54

Which of the ways to organize the storage of addresses and passport data should you choose?

Good day, dear users.
The question arose of how to organize the storage of addresses and passport users in the database.
At the moment, the addresses are stored as an array and are written to the json field in the database all at once

addresses: {
                        isAddressSimilar: false, //Адрес регистрации совпадает с адресом проживания
                        isAddressPlaceOfStay: false, //Адрес регистрации совпадает с адресом регистрации по месту пребывания
                        registration: {//Адрес регистрации
                            area: null,
                            city: null,
                            index: null,
                            region: null,
                            street: null,
                            housing: null,
                            settlement: null,
                            house_number: null,
                            apartment_number: null
                        },
                        residential: {//Адрес проживания
                            area: null,
                            city: null,
                            index: null,
                            region: null,
                            street: null,
                            housing: null,
                            settlement: null,
                            house_number: null,
                            apartment_number: null
                        },
                        place_of_stay: {//Адрес регистрации по месту пребывания
                            area: null,
                            city: null,
                            index: null,
                            region: null,
                            street: null,
                            housing: null,
                            settlement: null,
                            house_number: null,
                            apartment_number: null
                        },
                    },

Same story with passport details.
passport: {
                        nationality: 'russia',
                        documentType: 'RfPassport',
                        series: null,
                        number: null,
                        issuanceDate: DateTime.local().toISODate(),
                        subdivisionCode: null,
                        issued: null,
                        birthPlace: null,
                    },

The question is, is it correct to store data in the form of a json array in the users table, or does it make sense to create separate tables, where each field is a separate field from the array and pull data through links?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Chesnokov, 2019-07-31
@SpaceJesus

Most likely, the type of storage depends entirely on several factors:
In my opinion, in view of the foregoing, this type of information should be broken up into small pieces and put into separate tablets. And let the preachers of the doom of relational models laugh at me - I'm a stubborn conservative.

I
Igor Vorotnev, 2019-08-01
@HeadOnFire

Pavel Chesnokov speaks the matter, but in fact:
- User hasOne Passport / Passport belongsTo User (OneToOne connection)
Addresses are a bit more complicated, here I would store the addresses themselves separately through the OneToMany connection, with an additional type property. But isAddressSimilar and isAddressPlaceOfStay are either flags in the User, or a dynamic property in general - for example, if there is no address entry with the place_of_stay type, then we use the default (registration) or simply return false. For to store records where all columns except PK null it not apprx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question