Postgres - Table design to store user wise folder structure - postgresql

Im going to create a design for an application that looks like a Google drive, anyone can create files on the root directory or creating inside folders (and subfolders)
Now on the user's console, I have to show all the top level folders, a down arrow will be there, it the folder contains any subfolder, then if we click the down arrow, all the subfolders inside the folder will be visible.
Sample:
Im not sure, what kind of Table design I should choose for this, can someone help me with this?

You can create a self referencing hierarchical table for that. There will be parent_id column to store the id of parent folder. For top level folder parent_id will be null.
Below can be the list of columns for your table.
1. id -- integer auto increment primary key.
2. Name -- Name of the folder
3. Parent_id -- id of parent folder. Referencing id column of this table. Null for top level folders.
4. Sequence_Number -- In which sequence folders will be displayed. Folder with same parent_id will be displayed order by seqeunce_number. You can change it from front end so that user can choose to rearrange folder sequence.
5. description -- description of a folder. If you want to put it.
6. user_id -- Foreign key to user table.

Related

I want to Store folder name while copying data from S3 bucket to Redshift table

I am trying to load data from S3 bucket to redshift table,there is one column as source id in the table and i want to store the folder name where the source file is available,in to that column.
Actually i have multiple folders in S3 bucket and in each folder i have one file and i port all the files in same table with copy command in redshift, so to identify from which folder the data is, so i need to store the folder name along with data into the Redshift table, i have seperate column in table as Source id.
can any body help me.
If you are using the Redshift copy command, then you have no choice other than a process to import each folder (e.g. as a temp table) and then set your value manually the the value of the folder that you restored. repeat for each folder.
Another option is to use redshift spectrum and create an external table that maps to your folder as partitions.
first you create your base table like this
create external table spectrum.sales_part(
salesid integer,
listid integer,
sellerid integer,
buyerid integer,
eventid integer,
dateid smallint,
qtysold smallint,
pricepaid decimal(8,2),
commission decimal(8,2),
saletime timestamp)
partitioned by (saledate date)
row format delimited
fields terminated by '|'
stored as textfile
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/'
table properties ('numRows'='172000');
Then you add partitions to it like this
alter table spectrum.sales_part
add partition(saledate='2008-01-01')
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/saledate=2008-01/';
alter table spectrum.sales_part
add partition(saledate='2008-02-01')
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/saledate=2008-02/';
alter table spectrum.sales_part
add partition(saledate='2008-03-01')
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/saledate=2008-03/';
Once you have that set up as an external table, you can use standard sql against that table, for example you could run your queries against that table or copy it to a permanent redshift table using CTAS.
Here is a link to the documentation
https://docs.aws.amazon.com/redshift/latest/dg/c-spectrum-external-tables.html

Creating Database Table From Existing Database Table in progress

create table ABC
(
sno integer,
name character,
dob Date
)
I have a Database table name ABC.
Now, I want to create same Database table as name TEST In progress (Openedge).
Can any one help me here to complete this task?
In Oracle:
Create Table TEST As Select * from ABC;
How to create TEST table in progress OPenedge.
In Data Administration, go to Admin - Dump Data and Definitions - Data Definitions (.df file).
Choose your table ABC and click OK.
Enter an output file and choose OK.
Open the output file in a text editor (the Progress Procedure Editor will work.)
Do a search for "ABC" and replace all instances with "TEST". Save this file.
Go back to Data Administration. Choose Admin - Load Data and Definitions - Data Definitions (.df file).
Choose your edited file and click OK. The new TEST table should be loaded into the database.
OpenEdge SQL also has "CREATE TABLE AS SELECT" syntax. You can use it to create a copy of a table. Example:
SQLExplorer>create table pub.custcopy as select * from pub.customer;
SQLExplorer>
SQLExplorer>select top 5 name from pub.custcopy;
Name
----------------------------------------
Lift Line Skiing
Urpon Frisbee
Hoops Croquet Co.
Go Fishing Ltd
Match Point Tennis

Should I put my .mdf and .ldf files from my code into Visual Studio Team Services repository

If I create a .sqlproj file that contains all my sql objects, why would I need to put my mdf, ldf files into VS Team Services source repository? Doesn't the .mdf contain all the data? If that is true then I probably wouldn't want to store all the data in my repo? I can always publish the database to localdb if I need to recreate the database right? What are the best practices here?
You would not source control the actual .MDF and .LDF files; they contain your actual data.
However, there are use cases when it is desirable to control where on disk your .MDF and .LDF file exist. In such a case, it may make sense to include a FileGroup File defining the location of your MDF/LDF files in your .sqlproj file.
For example, assume you have a large D: drive where you wish to store data, and a speedy E: drive made up of SSDs where you wish to store your indexes. From your .sqlproj Storage folder, you might:
Add New Item > FileGroup, and create a file group called Data
Add New Item > FileGroup, and create a file group called Index
Add New Item > FileGroup File, and create a file called $(DatabaseName).Data.ldf
Add New Item > FileGroup File, and create a file called $(DatabaseName).Indexes.ldf
Then, you can modify your tables to include an ON {FileGroup} clause like this:
CREATE TABLE [dbo].[MyTable] (
MyTableID INT IDENTITY(1,1) NOT NULL,
OtherIndexField NVARCHAR(50) NULL,
...
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ([MyTableID] ASC)
) ON [Data];
CREATE NONCLUSTERED INDEX [IX_MyTableByOtherIndexField]
ON [dbo].[MyTable]([OtherIndexField] ASC)
ON [Index];

Revision control of data inside Lightswitch

I'm developing a Lightswitch application that will be accessed by different users. Some background info..
When a user make some changes to one or multiple rows he/she should be able to save those changes to a "temp file", without the main data being affected. Like if you're working with an Excel document and choose "Save as", the original file will still be there. The app should be able to handle multiple of those "savings". Then the user can open of of these "savings" and apply them to the main database.
My plan to accomplish this is to have multiple rows for the same data and having columns with user data, revision etc. Tho my main concern here is how to let the user choose which "saving" to open when entering the application and then filter out the correct data. Do I need to do a custom control to accomplish this, anyone that could give me some opinions? Kinda new in the Lightswitch area.
Thanks
I'm using Lightswitch to develop a quoting interface that implements revision control. They way I do it is to have a parent table that contains a list of all the quotes (this would be similar to an Explorer window full of Excel spreadsheets i.e. data.xls, data(1).xls, data(2).xls, etc.). Each of which has a unique ID and a revision number. The details of each revision of each quote are held in a child table that has a foreign key relationship linking it to the unique ID of a particular revision of a particular quote.
When a user logs in, they are presented with a grid view of all revisions of their quotes. When they select a particular quote revision, the unique ID of that entry is used as a parameter in all of my filter queries on the details of that quote, which are presented on a different screen.
My tables are created like this:
create table Quotes (
"QuoteID" uniqueidentifier
not null primary key,
"QuoteNumber" nvarchar(8)
not null,
"QuoteRevStart" date
not null,
"QuoteRevEnd" date,
"QuoteRevNumber" tinyint
not null,
"QuoteRevCurrent" bit
not null
)
create table QuoteDetails (
"QuoteDetailsID" uniqueidentifier default newid()
not null primary key,
"QuoteNo" uniqueidentifier
not null foreign key references Quotes(QuoteID),
"ItemNo" smallint
not null,
"ProductQty" smallint
not null,
)
This is based on Type 6 Slowly Changing Dimensions database design. All of this is done with standard Lightswitch controls.

How to create a report with sections and page breaks using SSRS

I'm trying to create a report that looks like this:
using a select from this table: (fiddler here for query and data)
CREATE TABLE StudentData
(
id int PRIMARY KEY IDENTITY,
name varchar(30),
subject varchar(30),
currentGrade varchar(2),
targetGrade varchar(2),
note1 varchar(100),
note2 varchar(100),
note3 varchar(100),
UNIQUE (id)
)
Basically I want to display each student on a new page, with their subject split up into sections, and their grades and notes in each of these subject sections.
I am trying to do this within Business Intelligence Development Studio
Any help with how I would go about that would be great, thanks.
I can upload the images now.
First you add a List Tablix to the report with the name and add a TextBox
Add a Parent Group to the list in the Row Group category
Choose name as the Group By Column
You will have two columns, one with the group and another with the TextBox created previously
Add more TextBox with the rest of the columns missing.
Now we're going to set the break on each group, select on the Row Groups section the group name and right click and select Group Properties
Select the Page Break page and then check the option Between each instance of a group
You should have something like this now.
Now let's configure the name to appear to the top of each page, select in the Row Groups section the Details Group and add a Total Before
And after add some TextBox and some colors you will have something like this.
I hope this can help you.
Add a List and set the DataSetName to your existing Dataset. In the Row Groups definition for the list, tell it to Group on id. Add a textbox for the name.
Add another List inside the existing List and set the DataSetName to your existing Dataset. In the Row Groups definition for the list, tell it to Group on subject. Add a textbox for the subject.
Add 2 Tables inside the inner List to present your inner-most tables.