I'm developing a list of import processes that has two databases: maritime and aerial. I created a database (Processes) that joins these two bases. Each process has a cnpj that is the identifier of a company that made the import. The idea is to have a column that identifies the largest consignee of each importer.
I have already created a general ranking. But the idea is to filter each consignee's cnpj and search for its biggest freight forwarder.
Database aerial:
Database Maritime:
Database processes:
Database consignee:
Database Agent:
Related
I want to create a small app that creates a kind off receipt record in to a db table, from two other tables. very much like a receipt from a grocery store where a cashier makes a sell and the ticket contains multiple items, calculates a total and subtotal and return values to the database. I currently have 3 tables: the Ticket table where i would like to insert the values of all calculations and ticket info, the services table that acts like an inventory of services available. this has the service name and price for each service and my responsible table that has a list of "cashiers" or people that will make the sale and their percentage for their commissions, i have the views to create , edit and delete cashier's and services.
What I don't have is a way to create the ticket. I am completely lost. can you guys point me in to the correct path on what to look for. i am learning to program son i don't have a lot of knowledge in this if its even possible. i don't need the system to print i just want to have all record stored this way later on i can expand on it and create reports of sold items and who sold them and how much commissions each seller has won.
You need to create relationships to two other models (tables) from the Ticket model (table). Luckily you don't have to create the relations in the database tables itself. Use django model's Foreign key fields to accomplish this. Here is the documentation link:
Django Models
You may need to read it several times to get the concepts thoroughly.
I have two distinct Django Apps, each one completely working separated. Those Apps are "PointOfSale" and "Inventory". What occurs is that both of these Apps have a "Product" table, in which the products are inserted. Now, keeping those two tables filled with basic the same data is obvious redundant (actually, the Inventory table of Products have more fields).
I'm now contemplating the different merge strategies to deal with this issue and I would like some help. Ideally, I would like to keep the possibility of each App working independently. So, I envisioned the following scenarios:
A Save Signal that keep the two tables insync
The connection of the two with OneToOne connection
Generic Relationship
The creation of a third App, called Products, in which the tables Products and CategoryOfProducts are kept, and both the Apps PointOfSale and Inventory uses it as a prerequisite.
MErge everything in one big App.
Another that I couldn't think of.
Thanks
I think the best way is to use the same database table from both Product models. See how you can have multiple databases in apps: https://docs.djangoproject.com/en/1.10/topics/db/multi-db/#an-example
So say AppA uses DB_A and AppB uses DB_B as databases for their unique models and that Product model/table is in DB_A. You can configure AppB to use DB_A for Product model while keeping DB_B for other models.
Ideally, if the models are the same, you can package Product app so that the same code is used in all projects.
I am building service oriented system, with multiple services and application.
Current I am not sure how to handle DB references between resources from multiple services and databases.
For example, I have a users service, where I can define all users and their roles.
Next I have, products service, where I can define my products, their prices and other information.
I also have invoicing service, which is used to create invoices. This service will use information from previous two services. It will link products and users to invoice. Now I am not sure what is the best approach for this?
Do I just save product ID and user ID that it got from other two services, without any referential integrity?
If I do this, then I will have problem when generating reports, because at time of generation I will need to send a lot of requests to products service, to get names and prices of product in invoice. Same for users.
Do I create some table products in my invoicing application, and store name and price of product at the moment of invoice creation?
If I go with this approach, then in case that price or name of product changes, I will have inconsistent data across my applications?
Is there some well-known pattern for this kind of problem, that is what is the best solution.
Cross-service references in DB is a common challenge for Data integrity between multiple web services, And specially when we are talking about Real time access.
There is two approaches for your case :
1- Databases Replication across your servers
I suppose that you have each application hosted on a separate server, So i can name your servers as Users_server, Products_server and Invoices_Server.
In your example, your Invoice web service need to grab data from Users & Products Servers, in this case you can create a Replication of your Users Database and Products Database on your Invoices_server.
This way you can run your Join queries on the same server and get data from multiple databases.
Query example :
SELECT *
FROM UsersDB.User u
JOIN InvoicesDB.Invoice i ON u.Id = i.ClientId
2- Main Database Replication
1st step you have to replicate all your databases into one main server we can call it Base_server, which basically contain all your databases from all your services.
Then you can build an internal web service for your application to provide needed data in just "One Call", this answer your question about generating reports.
In other words, you will make one call to the mane Base service instead of making 2 or 3 calls to your separate services.
Note: As a Backend developer we use this organization as a best practice while building a large bundle based application, we create a base bundle and then create service_bundle which rely on the base bundle.
If your services are already live, we may need more details about the technology and databases type you using in order to give you a more accurate solution.
Just because you are using SOA doesn't mean you abandon database integrity. Continue to use referential integrity where your database design requires it.
At the service level, you can have each service be responsible for returning identity information for the entities which it owns. This identity information may or may not be the actual primary key from the database, but it will be used by the clients of the service as though it were the actual primary key.
When a client wants to create an invoice, it will call the User service and receive a User entity, which will contain a User Identifier. It will call the Product service and receive a set of products, each with a product identifier. It will then call the Invoice service to create an invoice, passing the user identifier and the product identifiers. This will likely return an invoice identifier.
You can (probably should) enforce the integrity making the productId and userId foreign keys in your invoice table. Then your DB makes sure the referenced entities exist. Reports should join tables, not query services for each item. I assume a central DB shared across the system.
I think this is a recurrent question in the Internet, but unfortunately I'm still unable to find a successful answer.
I'm using Ruby on Rails 4 and I would like to create a model that interfaces with a SQL query, not with an actual table in the database. For example, let's suppose I have two tables in my database: Questions and Answers. I want to make a report that contains statistics of both tables. For such purpose, I have a complex SQL statement that takes data from these tables to build up the statistics. However the SELECT used in the SQL statement does not directly take values from neither Answers nor Questions tables, but from nested SELECTs.
So far I've been able to create the StatItem model, without any migration, but when I try StatItem.find_by_sql("...nested selects...") the system complains about unexisting table stat_items in the database.
How can I create a model whose instance's data is retrieved from a complex query and not from a table? If it's not possible, I could create a temporary table to store the data in there. In such case, how can I tell the migration file to not create such table (it would be created by the query)?
How about creating a materialized view from your complex query and following this tutorial:
ActiveRecord + PostgreSQL Materialized Views
Michael Kohl and his proposal of materialized views has given me an idea, which I initially discarded because I wrongly thought that a single database connection could be shared by two processes, but after reading about how Rails processes requests, I think my solution is fine.
STEP 1 - Create the model without migration
rails g model StatItem --migration=false
STEP 2 - Create a temporary table called stat_items
#First, drop any existing table created by older requests (database connections are kept open by the server process(es).
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS stat_items')
#Second, create the temporary table with the desired columns (notice: a dummy column called 'id:integer' should exist in the table)
ActiveRecord::Base.connection.execute('CREATE TEMP TABLE stat_items (id integer, ...)')
STEP 3 - Execute an SQL statement that inserts rows in stat_items
STEP 4 - Access the table using the model, as usual
For example:
StatItem.find_by_...
Any comments/improvements are highly appreciated.
My database have 6-7 tables on server side. i want only few 10-50 list of customers which is get me by store procedure (selecting records by joining of 6-7 tables).
I created application(used in both online & offline environment) which is sync up table from server to client vise versa. Which is displaying that customers name in combo box (records from stored procedure).
I am using sync framework. but this 6-7 tables contain huge records near around 67k. I don't want to sync up that 6-7 table. I want to sync up only those list of customer as per the login user.
I created one table like:
Customer_List user_Id Customer_Name customer_Id
and stored procedure return list of customers as per above table structure:
I want to sync up this table with my stored procedure using sync framework.
How I can do this?
there is on publicly available API in Sync Framework for you to specify/invoke a custom stored proc.
seems like what you're SP does can be represented as a Filter...
e.g., side.CustomerId IN (SELECT CustomerId FROM Customer_List WHERE User_Id =#User_Id)