![]() One of the first things database developers learn is the need for a primary key, a field that is guaranteed to be unique and indexed, and that can be used to identify a complete record. Even if you aren’t a Rails or PostgreSQL user, I hope these examples will give you a chance to think about how much you can and should expect from your database, as opposed to handling it from within your application. In this article, I introduce a number of these features, both from the perspective of a Rails developer and from that of a PostgreSQL administrator and DBA. However, the fact that Heroku offers a free tier for tiny data sets, and that it uses PostgreSQL by default, has made it a popular option for people learning Rails, for small applications and for many people who want to outsource their hosting.Īs as result of PostgreSQL’s growing popularity, the latest (4.x) version of Ruby on Rails includes extensive, built-in support for many PostgreSQL features. Whether Heroku is an appropriate choice for your application is a decision that should be made on a case-by-case basis. However, I’m guessing that it also has to do with the fact that Oracle now owns MySQL, along with the growth of the popular Heroku hosting service. This is partly due to the large (and constantly growing) feature set that PostgreSQL provides. The downside of such platform independence is that special features often are ignored, and indeed, in order to serve the lowest common denominator, many of PostgreSQL’s features were ignored or relegated to third-party gems.ĭuring the past few years, PostgreSQL has grown in popularity, both overall and within the Rails community. Indeed, one of my favorite Rails features always has been database migrations, which allow developers to change a database schema incrementally. As a result, Rails didn’t offer any support for PostgreSQL-specific features. When I started to develop using Ruby on Rails, most of the other developers (including the core Rails developers at 37Signals) were using MySQL. It’s also a platform supporting the storage and retrieval of many types of data, built on a rock-solid, ACID-compliant, transactional core. PostgreSQL is no longer just a relational database. As for PostgreSQL, I’ve been using it for about 15 years, and I continue to be amazed by the functionality it has gained in that time. Rails has been my primary server-side Web development framework for about eight years, and it has managed to provide solutions for a large number of consulting and personal projects. ![]() If we ever need to increase this, the change would be as simple as increasing the length in our ID generator and updating our database schema to accept the new size.Regular readers of this column won’t be surprised to hear that I love both Ruby on Rails and PostgreSQL. This gives us a 1% probability of a collision in the next ~35 years if we are generating 1,000 IDs per hour. In our case, we used the NanoID collision tool and decided to use 12 character long IDs with the alphabet of 0123456789abcdefghijklmnopqrstuvwxyz. Determining the complexity needed for the ID depends on the application. The longer and more complex the ID, the less likely it is to happen. If this is happening often though, it can be a huge problem. The application can detect a collision, auto-generate a new ID, and move on. If this happens seldomly, it’s not a big deal. These are much more user-friendly in a URL: /v1/deploy-requests/izkpm55j334u ID length and collisionsĪn ID collision is when the same ID is generated twice. ![]() This led us to NanoID, which accomplishes exactly that. ![]() Easy to generate in multiple programming languages (we use Ruby and Go on our backend).It may seem minor, but to build a product that developers love to use, we need to care about details like these. The browser interprets it as 5 different words. ![]() Try double clicking on that ID to select and copy it. UUIDs are great because it’s nearly impossible to generate a duplicate and they obscure your internal IDs. The common solution to this problem is using a UUID (Universally Unique Identifier) instead. We knew that we wanted to avoid using integer IDs so that we wouldn’t reveal the count of records in all our tables. When we were first building PlanetScale’s API, we needed to figure out what type of identifier we’d be using. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |