I am trying to achieve the same as these guys did: https://uniswap.org/blog/ipfs-uniswap-interface/
So first I read this:
https://docs.ipfs.io/concepts/ipns/
It says:
IPNS is not the only way to create mutable addresses on IPFS. You can
also use DNSLink, ...
So I went to read https://dnslink.io/, and then added a TXT _dnslink dnslink=/ipfs/<CID> entry to my DNS records.
Works perfectly.
But what about an update to content - won't the CID change? Do I have to update the TXT record every time the content changes? Is there a way to have the dnslink record point to always the last release?
https://uniswap.org/blog/ipfs-uniswap-interface/ says:
That TXT record contains the IPFS hash of the latest release.
So it suggest that it needs to be updated all the time. Maybe there is a programmatic way to update the TXT record so they don't have to go in all the time and change the hash?
Sligthly confused ¯_(ツ)_/¯
You can either:
Update the /ipfs/ CID in the TXT every time, programmatically or otherwise. Or, use an /ipns/ CID. With IPNS, you never need to update the TXT, but you need at least 1 IPFS node with the IPNS key to be online most of the time to regularly publish the IPNS record. If you do use IPNS, I recommend generating a new key for the content, not using the default node keypair. This makes it easier to move / copy the key.
Related
I recently discovered the wonders of foreign keys and deletion cascading with InnoDB and I love it. It helps me easily delete intricate data structures without worrying about leaving junk behind.
I'm currently storing images for a products database (like you would have on a web-shop) in the following manner:
My products table is what you would expect, it has an id primary column.
My product_images table has a product_id column with a foreign key to the products.id column, and an image column of type varchar storing the image file name.
The file names are created by computing the SHA1 hash of the image, then storing in a folder named after the first 2 characters of the hash:
61/6153A6FA0E4880D9B8D0BE4720F78E895265D0A9.jpg. In the database, only 6153A6FA0E4880D9B8D0BE4720F78E895265D0A9.jpg is stored.
Now, if I were to delete a product from the database, the cascading DELETE rule would delete the record in the product_images table, but would leave the file on my server.
Is there a way to automate the deletion of the image file whenever a record in the product_images table is deleted, be it specifically or by cascading? Maybe link some kind of trigger or routine to the deletion operation?
There is no native functionality built into mysql to perform this. If there were, there would be no end in sight to turning it into feature-creep and a full blown high-level programming language. Bloat-ware, getting away from its core competency.
People have used UDF libraries compiled in C that integrate into mysql either as object files or compiled into the server source. See the sections Adding New Functions to MySQL, and UDF Repository for MySQL. It become like a science fair project, where after you get it to work once, you probably won't want to roll it out to a fleet of other servers.
So what are you alternatives? The safe bets are always to write to another table (outside of your cascade delete hierarchy) the directory/filename combo. And have another mini-system do the housecleaning for you. For instance, twice a day, in Java or c# or python (any language). Those environments have db libraries, and robust file operations. It will be tremendously easier that way anyway.
I do these type of things to extend the functionality of mysql-related activities that are primarily file based or forbidden calls inside of stored procedures and events.
You would use below code for deleting the specific file.
Note: your file name ($filName) would come from your query.
$filName;
$dirName = substr($filName, 0, 2);
chown($filName,465);
unlink("../".dirName."/" . $filName);
when inserting images to DB change it's name to be linked with it's product
or it's category .
when deleting category search for imaged that have names involve cat id then unlink it
this code can help
foreach(glob(IMG_PATH.'cat_'.$_POST['id'].'*.*') as $file)
{
if(is_file($file))
{
#unlink($file);
}
}
I am creating a web application using Strongloop using a MySQL database connector.
I want it to be possible, that a user can modify data in the application - but that this data will not be 'saved' until a user expressly chooses to save the data.
On the other hand, this is a web application and I don't want to keep the data in the user's session or local storage - I want this data to be immediately persisted so it can be recovered easily if the user loses their session.
To implement it I am thinking of doing the following, but I'm not sure if this is a good idea, or if there is a better way to be doing this.
This is one was I can implement it without doing too much customization on an existing relation:
add an new generated index as the primary key for the table
add a new generated index that represents the item in the row
this would be generated for new items, or set to an old item for edits
add a boolean attribute 'saved'
Data will be written as 'saved=false'. To 'save' the data, the row is marked saved and the old row is deleted. The old row can be looked up by it's key, the second attribute in the row.
The way I was thinking of implementing it is to create a base entity called Saveable. Then every Database entity that extends Saveable will also have the 'Saveable' property.
Saveable has:
A generated id number
A generated non id number - the key for the real object
A 'saved' attribute
I would then put a method in Savable.js to perform the save operation and expose it via the API, and a method to intercept new writes and store them as unsaved.
My question is - is this a reasonable way to achieve what I want?
I've grabbed a load of tweets using the sample api. That's great. I know how to 'chuck' the tweets that are actually notifications of a tweet being deleted, but there lots of other cases, and who knows when another will be added? The cases are infact mentioned here:
Tweets can be embedded, replied to, favorited, unfavorited, retweeted, unretweeted and deleted.
How do I know though that I've got a POTO (Plain Old Twitter Objects) and not a delete, favourite etc. ?
Is there a standard process that could identify this? The Delete tweet for instance starts with {"delete":{.... so I can match for that as a string or try and look it up as a key (on JSON-Simple, it's done like so). What would be nice if all the POTOs started
{"tweet":{.... then I could pick them out, not have to discard anything that wasn't a POTO(needing a check for every single non-POTO).
I could just use the key checker to find every key that I need, and hope that it's relevant and correct (for instance both a the tweet body and the tweeter/user has an id, unless it's a delete then it's a id and user_id. To get both you need to go into the entities). But if I'm using Storm (and I am going to be eventually) I may end up plugging a bolt on later on, I then have to go back and change my checks.
So, is there a simple way to distinguish a tweet that's a tweet (POTO) and not something else?
As we all know that cakephp has default save command for inserting record into the database.
But i want to know can i create my own save command in cakephp or modify the existing one.
Can I do this?
You must be asking why i'm asking why i'm saying that? let me give you an live example for this----
Suppose i have an textbox which contains the username entered by the user.I'm not taking this as unique, hence more than one user will insert same username(possible..).
Ex-My name is prakash Gupta and i'm taking the username 'prakash'. There will be other users also whose name can be prakash gupta and they will provide the same username.Now inorder to solve this i'm using random function and attaching some digits behind the username, so that
it will be different for every one.
Now 'save' command will take the username which i entered in the textbox and insert into the database but i want to insert the modified username into the database which i generated
by random function. can this be possible???
if yes let me know....
Normally you don't change the standard one but either add another one or use the beforeSave etc. hooks.
The save functions are part of the Models. Normally you modify them with: Behaviors. See: http://book.cakephp.org/2.0/en/models/behaviors.html They let you modify the models, saving etc. without having to code all directly into your models.
Based on your edit:
Unique constraint
As I see you want a unique username. There are multiple solutions for that. First make sure to set a constraint. Even your random() trick will possibly generate a duplicate since random can create also the same. So username.random(4) could generate multiple times: username1234. You cannot be sure.
Constraints should be set at for example your model level. Start this unique check with validations of CakePHP.
When do you know the username is already used
You will know when the validation failed. So first just validate the record. So before save call model::validate() to check whether your unique constraint is ok. If yes just save.
http://book.cakephp.org/2.0/en/models/data-validation.html
If not you can add your random string and check again. Call model::validate to see if it is now ok. This part could be implemented for example in a behaviour in the beforeSave() method.
Now you have a unique one save your record. Make sure to check whether it succeeded because it is possible that in the meantime another record with that username was added. In that case re-run the process.
Lots of work
It is hard because multiple clients can add data same time in a database before you even know. Most simple is to catch the error, so just call save with your username. If it fails because of your unique constraint add the random() string and try again and again. It should be possible to save. Trick here with your random string because if it is short and a username is used a lot you can run into issues. If your random string is 3 numbers you can have the same username 1000 times, from 000 to 999.
Other option
What you sometimes see is suggestions, the interface suggests some free names based on your username input. You still need the check though.
Another option
Just tell the user it is in use. Maybe add an ajax check so you can instantly show the result by validating the field.
Ok this is a tricky one to explain.
I am creating an app that will have PAGES, currently I'm using PageID as the key to SEL the record.
The issue I'm having now is that I want users to be able to EDIT pages, but not lose the previous page (for history, recording keeping reasons, like a changelog or wiki page history).
This is making me think I need a new field in the PAGE table that acts as the pageID, but isn't the Primary Key that is auto-incremented every time a row is added.
Google Docs has a DOCID: /Doc?docid=0Af_mFtumB56WZGM4d3Y3d2JfMTNjcDlkemRjeg
That way I can have multiple records with the same Doc ID, and show a history change log based on the dataAdded field. And when a user wants to view that DOCID, I simply pull the most recent one.
Thoughts? I appreciate your smart thinking to point me in the right direction!
You're on the right track. What you need is a history or revision id, and a document id. The history id would be the primary key, but you would also have a key on the document id for query purposes.
With history tracking, you add a bit more complexity to your application. You have to be careful that the main view of the document is showing the current history revision (ie. largest history id for a given document id).
As well, if you are storing large documents, every edit is essentially going to add another copy of the document to your database, and the table will quickly grow very large. You might want to consider implementing some kind of "diff" storage, where you store only the changes to the document and not the full thing, or keeping history edits in a separate table for history-searching only.
UUID() creates a randomly generated 128bit number, like
'6ccd780c-baba-1026-9564-0040f4311e29'
This number will not be repeated in a few millions years.
//note most digits are based upon timestamp and machine information, so many of the digits will be similar upon repeated calls, but it will always be unique.
Keep an audit table with the history of the changes. This will allow you to go back if you need to roll back the changes or view change history for example.
You might model it like this:
An app has multiple pages, a page has multiple versions (each with some version info (e.g., date, edit count), and a foreign key to its page)
Viewing a page shows the most recent version
Saving an edit creates a new version
each document is really a revision:
doc - (doc_id)
revision - (rev_id, doc_id, version_num, name, description, content, author_id, active tinyint default 1)
then you can open any content with just the rev_id: /view?id=21981
select * from revision r, doc d where r.rev_id = ? and r.doc_id = d.doc_id
This sounds like a good job for two tables to me. You might have one page_header table and one page_content table. The header table would hold static info like title, categorization (whatever) and the content table would hold the actual editable content. Each time the user updates the page, insert a new page_content record versus updating an existing one. When you display the page just make sure you grab the latest page_content record. This is a simple way to keep a history and roll back if needed.
Good luck!