๐ฅ YellowDuck.be | Posts & Reading Listhttps://www.yellowduck.be/posts/feed2024-03-28T20:30:46+01:00๐ Laravel Read / Write Connections use multi-database2024-03-27T15:13:55Zhttps://www.yellowduck.be/posts/laravel-read-write-connections-use-multi-database<blockquote>
<p>Sometimes you may wish to use backup database and live database for handling maximum user interaction</p>
<p>Out of the box Laravel always you to have read/write database connections. This will allow you to have different
database connections for SELECT queries and INSERT, UPDATE and DELETE queries.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Offload the majority of requests to your database with our newest update to Standby Nodes2024-03-27T11:15:54Zhttps://www.yellowduck.be/posts/getting-started-with-blockchain-technology<blockquote>
<p>Standby Nodes have always been a great failsafeโif your database fails for any reason, a constantly replicated and
completely up-to-date Standby Node is there, ready and waiting, to take its place. But what about when your database
is functioning fine?</p>
<p>In addition to replication, you can now use your Standby Nodes as Read-Only Nodes! Using an API connection string, you
can offload requests to your Standby Nodes and free up your primary database to manage only mission-critical requests.
As long as your primary database and Standby Nodes are housed in the same data center, Standby Nodes now operate as
Read-Only Nodes. (For read-only requests in a different data center, you'll still need to use <a href="https://waves.digitalocean.com/MTEzLURUTi0yNjYAAAGSGk3dhI7JfsqzuXaoZOc0WHB4zoa-LjGdNcENTvdch1vwZsOGm2g6DUeaom6cZJrsZK0m1aI=">Read-Only
Nodes</a>,
specifically.)</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ฅ Customizing email titles in Laravel console kernel scheduled tasks2024-03-26T17:00:00Zhttps://www.yellowduck.be/posts/customizing-email-titles-in-laravel-console-kernel-scheduled-tasks<p>Laravel provides a convenient way to <a href="https://laravel.com/docs/10.x/scheduling#main-content">schedule tasks</a>. Scheduled
tasks are vital for automating repetitive tasks like sending emails, generating reports, or performing database
maintenance.</p>
<p>By using the standard functionality, it's very easy <a href="https://laravel.com/docs/10.x/scheduling#task-output">to email the output of these
commands</a>. However, the email subject often needs to be customized
to provide more context to the recipient. In this article, we'll explore how to customize the email titles for scheduled
tasks in Laravel.</p>
<h1>Setting up Laravel console kernel</h1>
<p>Before diving into customization, let's ensure that Laravel console kernel is set up correctly. The console kernel
serves as the entry point for all Laravel console commands, including scheduled tasks.</p>
<p>To schedule a task, navigate to the <code>app/Console/Kernel.php</code> file in your Laravel project. Within this file, you'll find the <code>schedule()</code> method. This method allows you to define all of your scheduled tasks using a fluent API provided by Laravel's Task Scheduler.</p>
<h1>Defining scheduled tasks</h1>
<p>Inside the <code>schedule()</code> method, you can define your scheduled tasks using various methods provided by Laravel, such as
<code>command()</code>, <code>call()</code>, or <code>exec()</code>. For instance, let's consider a simple task that generates a report and sends it via
email:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#ff7b72">protected</span> <span style="color:#ff7b72">function</span> <span style="color:#d2a8ff;font-weight:bold">schedule</span>(Schedule <span style="color:#79c0ff">$schedule</span>)<span style="color:#ff7b72;font-weight:bold">:</span> void
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span>{
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span> <span style="color:#79c0ff">$schedule</span><span style="color:#ff7b72;font-weight:bold">-></span>command(GenerateReportCommand<span style="color:#ff7b72;font-weight:bold">::</span>class)
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">4</span><span> <span style="color:#ff7b72;font-weight:bold">-></span>daily()
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">5</span><span> <span style="color:#ff7b72;font-weight:bold">-></span>emailOutputTo(<span style="color:#a5d6ff">'your@email.com'</span>, onlyIfOutputExists<span style="color:#ff7b72;font-weight:bold">:</span> <span style="color:#ff7b72">true</span>));
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">6</span><span>}
</span></span></code></pre><p>In this example, we're scheduling the <code>GenerateReportCommand::class</code> to run daily and send its output to the specified
email address. We also use the option <code>onlyIfOutputExists</code> to send the email only if the command generates any output.</p>
<h1>Customizing Email Titles</h1>
<p>By default, Laravel uses the task description as the subject for emails sent via the <code>emailOutputTo()</code> method. However, you may want to customize this subject to provide more context or make it more descriptive.</p>
<p>To customize the email title, Laravel allows you to use the <code>description</code> method, where you can specify the email
subject:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#ff7b72">protected</span> <span style="color:#ff7b72">function</span> <span style="color:#d2a8ff;font-weight:bold">schedule</span>(Schedule <span style="color:#79c0ff">$schedule</span>)<span style="color:#ff7b72;font-weight:bold">:</span> void
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span>{
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span> <span style="color:#79c0ff">$schedule</span><span style="color:#ff7b72;font-weight:bold">-></span>command(GenerateReportCommand<span style="color:#ff7b72;font-weight:bold">::</span>class)
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">4</span><span> <span style="color:#ff7b72;font-weight:bold">-></span>daily()
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">5</span><span> <span style="color:#ff7b72;font-weight:bold">-></span>emailOutputTo(<span style="color:#a5d6ff">'your@email.com'</span>, onlyIfOutputExists<span style="color:#ff7b72;font-weight:bold">:</span> <span style="color:#ff7b72">true</span>))
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">6</span><span> <span style="color:#ff7b72;font-weight:bold">-></span>description(App<span style="color:#ff7b72;font-weight:bold">::</span>environment() <span style="color:#ff7b72;font-weight:bold">.</span> <span style="color:#a5d6ff">' | Report was generated'</span>);
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">7</span><span>}
</span></span></code></pre><p>In this example, we've added the <code>description()</code> method to the scheduled task, providing a custom email subject that
includes the current environment and a descriptive message. This way, the recipient can quickly identify the purpose of
the email.</p>
<h1>Conclusion</h1>
<p>Customizing email titles for scheduled tasks in Laravel console kernel is a simple yet powerful feature that enhances
the clarity and context of automated email notifications. By following the steps outlined in this guide, you can easily
tailor email subjects to suit your specific requirements, providing recipients with valuable insights and facilitating
better communication within your application.</p>
Pieter Claerhout๐ Setting Up a Multi-tenant Phoenix App for Elixir2024-03-26T06:52:05Zhttps://www.yellowduck.be/posts/setting-up-a-multi-tenant-phoenix-app-for-elixir-appsignal-blog<blockquote>
<p>Apps built with Elixir can support massive scalability, real-time interactivity, great fault tolerance, and the
language's syntax is actually a joy to use. Elixir is a natural fit for applications such as chat apps, data dashboard
apps, and anything needed to support a large userbase.</p>
<p>In this article, we'll use Elixir โ specifically, the web framework Phoenix โ to build a multi-tenant link shortening
app.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ The Developer's Guide to SSO โ WorkOS2024-03-21T15:34:13Zhttps://www.yellowduck.be/posts/the-developers-guide-to-sso-workos<blockquote>
<p>Adding SSO to your app is a common requirement for selling to enterprise customers. Here's a guide that will help you
understand SSO and choose the best way to add it to your app.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Vector Similarity Search with PostgreSQL's pgvector2024-03-21T12:32:16Zhttps://www.yellowduck.be/posts/vector-similarity-search-with-postgresqls-pgvector<blockquote>
<p>As the <a href="https://time.com/6310115/ai-revolution-reshape-the-world/">AI revolution</a> surges forward, promising
significant innovations, it also introduced new types of vector databases. A vector database stores data as
high-dimensional vectors called embeddings, which are mathematical representations of features or attributes of the
data. These vectors are generated by applying an embedding function to the raw data, such as text, images, audio,
video, etc. The embedding function can be machine learning models, feature extraction algorithms, etc.</p>
<p>We all know PostgreSQL as a relational database for transactional workloads. But, at the same time, with the pgvector
extension, you can turn PostgreSQL into a complete vector database to power your AI applications.</p>
<p>This blog will provide a high-level overview of vector search and its application before going in-depth on pgvector,
delving into its creation, features, use cases, and how to enable it into your
<a href="https://severalnines.com/clustercontrol/databases/postgresql/">PostgreSQL</a> database manually and using ClusterControl
(CC).</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ The 2038 Problem2024-03-18T08:21:29Zhttps://www.yellowduck.be/posts/the-2038-problem<blockquote>
<p>Remember the <a href="https://en.wikipedia.org/wiki/Year_2000_problem">"Year 2000" problem</a> (or Y2K) in the late 90s? This
referred to the fact that many older computer systems represented years using only two digits. This meant that when
the year 2000 arrived, many systems would incorrectly display it as "00" instead of "2000", causing errors with dates
and calculations.</p>
<p>While I was a teenager at the time, I was already into computers so it fascinated me and I was glued to the screen
reading about it. When the New Year eve hit... nothing happened. Life continued as normal, so all the non-technical
people around me said this "threat" was blown out of the proportion to make some news headlines. What I didn't know is
that behind the scenes there was a <a href="https://www.si.edu/spotlight/y2k#:~:text=Research%20firm%20Gartner%20estimated%20the,before%20midnight%20December%2031%2C%201999.">massive
efforts</a>
to remediate systems to avoid major disruptions when the actual date arrived.</p>
<p>This is a great example of <a href="https://en.wikipedia.org/wiki/Preparedness_paradox">"Preparedness paradox"</a>. When a
potential disaster is properly prepared for, it won't seem like a big deal after the fact. People will think the
precautions were unnecessary. But Y2K could have been a major catastrophe if nothing was done. Some estimates
suggested failures in key systems could lead to blackouts, air travel shutdowns, supply chain issues and even <a href="https://journals.sagepub.com/doi/full/10.2968/055002009">nuclear
missile system failures</a>.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ The Mac Admins Podcast team explain how to secure Apple devices at work and home2024-03-15T14:09:28Zhttps://www.yellowduck.be/posts/the-mac-admins-podcast-team-explain-how-to-secure-apple-devices-at-work-and-home-1password<blockquote>
<p>Joined by the popular <a href="https://podcast.macadmins.org/">Mac Admins podcast</a> cast, we dive into Apple security and
privacy, and how Macs are being integrated into workplaces everywhere. Find out whether an Apple product on its own
keeps you secure and safe from viruses, or if you need additional security apps to protect your devices.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Language Policy at Google: Let's Go!2024-03-15T09:10:30Zhttps://www.yellowduck.be/posts/language-policy-at-google-lets-go<blockquote>
<p>Last week, I wrote a post that was largely about how Google decides whether to support a programming language for
general use. I mentioned that languages developed by Google, like Go and Dart, and languages advocated by Google, like
Kotlin, were special cases. Sameer Ajmani (who is the director responsible for Go) challenged me to write about Go.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Go, Python, Rust, and production AI applications2024-03-15T09:06:37Zhttps://www.yellowduck.be/posts/go-python-rust-and-production-ai-applications<blockquote>
<p>In this article, I'll talk about Go, Python, and Rust, and each language's role in building AI-powered applications.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Generative AI for Contracts2024-03-13T14:43:29Zhttps://www.yellowduck.be/posts/generative-ai-for-contracts<blockquote>
<p>Generative AI models are not new, but when ChatGPT was launched on 30th Nov '22, it felt like a seminal moment in
adoption of AI. Since then, our teams have been playing around with the OpenAI chat interface / playground / APIs
while our leadership has been busy talking to as many contract professionals as possible.</p>
<p>We had two objectives:</p>
<ol>
<li>Define the specific high value application of these extremely powerful AI models (called as LLMs or Large Language
Models) in contracts</li>
<li>Figure out how to extract the best output from these models and integrate that elegantly into contract workflows</li>
</ol>
<p>In this article, we start by sharing two examples of powerful application of ChatGPT on complex contract analysis
work. We then share our ideas on the most impactful applications of Generative AI in contract management. Finally, we
share a sneak peek of how we are integrating OpenAI APIs into our Microsoft Word based product.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ System-wide text summarization using Ollama and AppleScript2024-03-13T12:25:05Zhttps://www.yellowduck.be/posts/system-wide-text-summarization-using-ollama-and-applescript<blockquote>
<p>Local LLMs like Mistral, Llama etc allow us to run ChatGPT like large language models locally inside our computers.
Since all the processing happens within our systems, I feel more comfortable feeding it personal data compared to
hosted LLMs.</p>
<p>A quick way to get started with Local LLMs is to use an application like <a href="https://ollama.com/">Ollama</a>. It's very easy
to install, but interacting with it involves <a href="https://github.com/ollama/ollama?tab=readme-ov-file#quickstart">running
commands</a> on a terminal or installing other <a href="https://github.com/open-webui/open-webui">server
based GUI</a> in your system.</p>
<p>These are not a huge dealbreakers, but wouldn't it be nice if you can select a piece of text in any application and
ask the LLM to summarize it?</p>
<blockquote>
<p>Wouldn't it be nice if you can select a piece of text in any application and ask the LLM to summarize it?</p>
</blockquote>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Laravel 11: the upgrade guide from version 102024-03-13T10:13:36Zhttps://www.yellowduck.be/posts/laravel-11-the-upgrade-guide-from-version-10<blockquote>
<p>Upgrading your Laravel applications to the latest version has many benefits like:</p>
<ul>
<li>Reduced bugs.</li>
<li>Reduced security risks.</li>
<li>Increased compatibility with first and third-party packages.</li>
</ul>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ฅ Checking your packages for Laravel 11 compatibility2024-03-12T17:00:00Zhttps://www.yellowduck.be/posts/checking-your-packages-for-laravel-11-compatibility<p>If you want to know if you are ready to update to Laravel 11, you can use this command to check if your packages are
compatible with the new version:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span>composer why-not laravel/framework 11.0
</span></span></code></pre><p>There is also an upgrade guide available at <a href="https://laravel.com/docs/11.x/upgrade">laravel.com/docs/11.x/upgrade</a>.</p>
Pieter Claerhout๐ I made a mistake2024-03-09T15:06:55Zhttps://www.yellowduck.be/posts/i-made-a-mistake<blockquote>
<p>Last month, I <a href="https://twitter.com/JackEllis/status/1752102668309557287">tweeted</a> that I had rolled all our email
report queries into one query, allowing us to deliver our email reports much faster.</p>
<p>Amazing, right?</p>
<p>Nope, let me share my mistakes.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ I don't get the point of Golang - That's why I need help2024-03-09T08:36:47Zhttps://www.yellowduck.be/posts/i-dont-get-the-point-of-golang-thats-why-i-need-help<blockquote>
<p>Hello everyone, I'm back. The past few days were crazy at my work, so many complicated tasks needed to get shipped and
I couldn't write here.</p>
<p>Today I'm coming up with a different topic: I don't get the point of Golang - and I need help with it.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ goqite - persistent message queue2024-03-08T12:35:01Zhttps://www.yellowduck.be/posts/goqite<blockquote>
<p><a href="https://www.goqite.com/">goqite</a> is a persistent message queue Go library built on SQLite and inspired by AWS SQS
(but much simpler).</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Get consistent data from your LLM with JSON Schema2024-03-08T09:31:13Zhttps://www.yellowduck.be/posts/get-consistent-data-from-your-llm-with-json-schema<blockquote>
<p>We recently started an internal project to gain experience with Large Language Models (LLMs) and generate content for
a role play-based application. If you are unfamiliar with LLM or AI in general, a good starting point could be <a href="https://thoughtbot.com/blog/what-llms-are-in-ai">Mike
and Steffani's article</a> on the topic.</p>
<p>One of our app's usages is to generate the structure of a new game such as the main character, the background story or
the first choice the player will have to face. From the generated content, we want to create objects and store the
data in database tables.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Get Started with Milvus Vector DB in .NET2024-03-08T07:27:33Zhttps://www.yellowduck.be/posts/get-started-with-milvus-vector-db-in-net-net-blog<blockquote>
<p>Vector databases have become an important component of Generative AI workloads powering scenarios like search and
Retrieval Augmented Generation (RAG).</p>
<p>The .NET team has worked closely with Milvus to enable .NET developers to use vector databases in their applications.</p>
<p>In this post, we'll show how you can quickly get started using the Milvus .NET SDK currently in preview.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ฅ Using non-integer primary keys in Eloquent2024-03-07T17:00:00Zhttps://www.yellowduck.be/posts/using-non-integer-primary-keys-in-eloquent<p>By default, Eloquent assumes that primary keys in your database tables are integers, typically auto-incrementing.
However, there are cases where you might need to use non-integer primary keys, such as UUIDs or strings. In this guide,
we'll explore how to leverage non-integer primary keys in Laravel Eloquent.</p>
<h1>Choosing a Non-Integer Primary Key</h1>
<p>Before diving into implementation, it's essential to understand why you might choose a non-integer primary key. Integer
primary keys work well for many applications, but there are scenarios where non-integer keys offer advantages. For
instance:</p>
<ul>
<li><strong>Universally Unique Identifiers (UUIDs)</strong>: UUIDs ensure globally unique identifiers across systems and databases,
facilitating easier data replication and synchronization.</li>
<li><strong>Human-Readable Keys</strong>: Sometimes, using meaningful strings as primary keys can enhance readability and user
experience.</li>
<li><strong>Integration with External Systems</strong>: When integrating with external systems or APIs that use non-integer
identifiers, it's pragmatic to maintain consistency.</li>
</ul>
<p>Once you've decided on the type of non-integer primary key that suits your application's needs, you can proceed with
integrating it into your Laravel Eloquent models.</p>
<h1>Defining Models with Non-Integer Primary Keys</h1>
<p>In Laravel, defining models with non-integer primary keys is straightforward. Let's say we have a products table with a
product_code column as the primary key, which contains unique alphanumeric codes for each product. We can create an
Eloquent model for this table as follows:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 1</span><span><span style="color:#ff7b72">namespace</span> App\Models;
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 2</span><span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 3</span><span><span style="color:#ff7b72">use</span> Illuminate\Database\Eloquent\Model;
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 4</span><span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 5</span><span><span style="color:#ff7b72">class</span> <span style="color:#f0883e;font-weight:bold">Product</span> <span style="color:#ff7b72">extends</span> Model
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 6</span><span>{
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 7</span><span> <span style="color:#ff7b72">protected</span> <span style="color:#79c0ff">$primaryKey</span> <span style="color:#ff7b72;font-weight:bold">=</span> <span style="color:#a5d6ff">'product_code'</span>;
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 8</span><span> <span style="color:#ff7b72">public</span> <span style="color:#79c0ff">$incrementing</span> <span style="color:#ff7b72;font-weight:bold">=</span> <span style="color:#ff7b72">false</span>;
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 9</span><span> <span style="color:#ff7b72">protected</span> <span style="color:#79c0ff">$keyType</span> <span style="color:#ff7b72;font-weight:bold">=</span> <span style="color:#a5d6ff">'string'</span>;
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">10</span><span>}
</span></span></code></pre><p>In the <code>Product</code> model, we specify the <code>$primaryKey</code> property to denote the primary key column name, set <code>$incrementing</code>
to false to indicate that the IDs are not auto-incrementing integers, and specify the <code>$keyType</code> as <code>string</code> to inform
Eloquent about the primary key's data type.</p>
<h1>Working with Relationships</h1>
<p>When working with relationships between models that have non-integer primary keys, Laravel provides seamless support.
You can define relationships using the hasMany, belongsTo, or other methods as usual, and Laravel will handle the
foreign key constraints appropriately.</p>
<h1>Querying Models</h1>
<p>Querying models with non-integer primary keys in Laravel Eloquent remains consistent with integer keys. For example, to
retrieve a product with a specific product code, you can use the find() method:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#79c0ff">$product</span> <span style="color:#ff7b72;font-weight:bold">=</span> Product<span style="color:#ff7b72;font-weight:bold">::</span>find(<span style="color:#a5d6ff">'ABC123'</span>);
</span></span></code></pre><p>Additionally, you can perform queries using Eloquent's fluent query builder methods, such as <code>where()</code>, <code>orWhere()</code>,
<code>whereIn()</code>, etc., without any modifications.</p>
<h1>Migrations and Database Setup</h1>
<p>When creating migrations for tables with non-integer primary keys, ensure that the primary key column is appropriately
defined. For instance, for UUID primary keys, you might use the uuid() method in your migrations:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span>Schema<span style="color:#ff7b72;font-weight:bold">::</span>create(<span style="color:#a5d6ff">'products'</span>, <span style="color:#ff7b72">function</span> (Blueprint <span style="color:#79c0ff">$table</span>) {
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span> <span style="color:#79c0ff">$table</span><span style="color:#ff7b72;font-weight:bold">-></span>uuid(<span style="color:#a5d6ff">'product_code'</span>)<span style="color:#ff7b72;font-weight:bold">-></span>primary();
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span> <span style="color:#8b949e;font-style:italic">// Other columns...
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">4</span><span><span style="color:#8b949e;font-style:italic"></span>});
</span></span></code></pre><h1>Conclusion</h1>
<p>In conclusion, Laravel Eloquent provides robust support for using non-integer primary keys, allowing developers to work
with a variety of data models and database structures seamlessly. By following the steps outlined in this guide, you can
integrate non-integer primary keys into your Laravel applications efficiently and take advantage of their benefits.</p>
<p>Whether you're using UUIDs, strings, or other non-integer identifiers, Laravel's flexibility empowers you to build
elegant and scalable solutions tailored to your specific requirements.</p>
<p>Happy coding!</p>
<h1>Resources</h1>
<ul>
<li><a href="https://laravel.com/docs/10.x/eloquent#primary-keys">Laravel Eloquent: Primary Keys</a></li>
</ul>
Pieter Claerhout๐ Distributed Systems Horror Stories: Kubernetes Deep Health Checks2024-03-07T15:50:16Zhttps://www.yellowduck.be/posts/distributed-systems-horror-stories-kubernetes-deep-health-checks-encore-blog<blockquote>
<p>Distributed systems are often described as a double-edged sword. There is plenty of excellent content out there
written on both why they suck and also why they are great. This is not one of those posts. I would say generally I am
an advocate and believer in distributed systems where they make sense, but the goal of this blog post (and the two
others that will follow) is to share some stories with you about where I have got something wrong within a distributed
system that has led to a far reaching impact.</p>
<p>In this first post, I will share a mistake that I have seen made in multiple companies now that can lead to cascading
failure. I call it the <strong>Kubernetes deep health check</strong>.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Steve vs Matt โ How two developers approach the same problem2024-03-07T11:48:35Zhttps://www.yellowduck.be/posts/steve-vs-matt-how-two-developers-approach-the-same-problem-laravel-news<blockquote>
<p>It's very common to see two programmers who code the same feature differently. But it's much less common for those two
programmers to see eye-to-eye and remain friendly. Thankfully, we have a chance to see how two friends approach the
same coding challenge differently and each friend's reflection on the other's code and approach.</p>
<p>Recently Matt shared an opinion on Twitter: <a href="https://twitter.com/stauffermatt/status/1597247009907683328">"Most interfaces in PHP code are completely
useless."</a> One respondent tagged Steve about his love for
interfaces, and Steve & Matt decided to write an article about how we each code.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ Feature flags are ruining your codebase2024-03-07T09:33:03Zhttps://www.yellowduck.be/posts/feature-flags-are-ruining-your-codebase<blockquote>
<p>So what's wrong with feature flags? Among other things:</p>
<ol>
<li>
<p>They give PMs an excuse to not make hard decisions, such as completely removing a feature.</p>
</li>
<li>
<p>The codebase becomes more complex and harder to maintain.</p>
</li>
<li>
<p>Testing becomes harder (and lower quality) - figuring out what combination of feature flags needs to be supported.</p>
</li>
</ol>
<p>Before I go on, the usual disclaimer: It's just the opinion of one guy, based on my own experience.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout๐ฅ Cancel in-progress jobs using GitHub Actions2024-03-06T17:00:00Zhttps://www.yellowduck.be/posts/cancel-in-progress-jobs-using-github-actions<p>When pushing new commits to a pull request, it's essential to manage ongoing jobs effectively to prevent resource
wastage and streamline the development process. In this blog post, we'll explore how you can utilize GitHub Actions'
concurrency options to automatically cancel in-progress jobs when pushing new commits, enhancing productivity and
resource management.</p>
<p>GitHub Actions provides concurrency options that allow you to control how workflows run in parallel. One such option is
<code>cancel-in-progress</code>, which automatically cancels in-progress jobs associated with previous workflow runs when new
workflow runs are triggered. By enabling this option, you can ensure that only the most recent workflow runs are
executed, eliminating redundancy and preventing conflicts.</p>
<h1>Using concurrency to cancel any in-progress job or run</h1>
<p>To use concurrency to cancel any in-progress job or run in GitHub Actions, you can use the <code>concurrency</code> key with the
<code>cancel-in-progress</code> option set to <code>true</code>:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#7ee787">concurrency</span>:<span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">group</span>:<span style="color:#6e7681"> </span><span style="color:#a5d6ff">${{ github.ref }}</span><span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">cancel-in-progress</span>:<span style="color:#6e7681"> </span><span style="color:#79c0ff">true</span><span style="color:#6e7681">
</span></span></span></code></pre><h1>Using a fallback value</h1>
<p>If you build the group name with a property that is only defined for specific events, you can use a fallback value. For
example, <code>github.head_ref</code> is only defined on <code>pull_request</code> events. If your workflow responds to other events in
addition to <code>pull_request</code> events, you will need to provide a fallback to avoid a syntax error. The following
concurrency group cancels in-progress jobs or runs on <code>pull_request</code> events only; if <code>github.head_ref</code> is undefined, the
concurrency group will fallback to the run ID, which is guaranteed to be both unique and defined for the run.</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#7ee787">concurrency</span>:<span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">group</span>:<span style="color:#6e7681"> </span><span style="color:#a5d6ff">${{ github.head_ref || github.run_id }}</span><span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">cancel-in-progress</span>:<span style="color:#6e7681"> </span><span style="color:#79c0ff">true</span><span style="color:#6e7681">
</span></span></span></code></pre><h1>Only cancel in-progress jobs or runs for the current workflow</h1>
<p>If you have multiple workflows in the same repository, concurrency group names must be unique across workflows to avoid
canceling in-progress jobs or runs from other workflows. Otherwise, any previously in-progress or pending job will be
canceled, regardless of the workflow.</p>
<p>To only cancel in-progress runs of the same workflow, you can use the <code>github.workflow</code> property to build the
concurrency group:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#7ee787">concurrency</span>:<span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">group</span>:<span style="color:#6e7681"> </span><span style="color:#a5d6ff">${{ github.workflow }}-${{ github.ref }}</span><span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">cancel-in-progress</span>:<span style="color:#6e7681"> </span><span style="color:#79c0ff">true</span><span style="color:#6e7681">
</span></span></span></code></pre><h1>Only cancel in-progress jobs on specific branches</h1>
<p>If you would like to cancel in-progress jobs on certain branches but not on others, you can use conditional expressions
with <code>cancel-in-progress</code>. For example, you can do this if you would like to cancel in-progress jobs on development
branches but not on release branches.</p>
<p>To only cancel in-progress runs of the same workflow when not running on a release branch, you can set
<code>cancel-in-progress</code> to an expression similar to the following:</p>
<pre style="color:#e6edf3;background-color:#0d1117;"><code><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">1</span><span><span style="color:#7ee787">concurrency</span>:<span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">2</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">group</span>:<span style="color:#6e7681"> </span><span style="color:#a5d6ff">${{ github.workflow }}-${{ github.ref }}</span><span style="color:#6e7681">
</span></span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">3</span><span><span style="color:#6e7681"> </span><span style="color:#7ee787">cancel-in-progress</span>:<span style="color:#6e7681"> </span><span style="color:#a5d6ff">${{ !contains(github.ref, 'release/')}}</span><span style="color:#6e7681">
</span></span></span></code></pre><p>In this example, multiple pushes to a <code>release/1.2.3</code> branch would not cancel in-progress runs. Pushes to another
branch, such as <code>main</code>, would cancel in-progress runs.</p>
<h1>More information</h1>
<ul>
<li><a href="https://docs.github.com/en/enterprise-cloud@latest/actions/using-jobs/using-concurrency">Using concurrency - Run a single job at a time</a></li>
</ul>
Pieter Claerhout๐ Renรฉ Roth | Composite indexes in Laravel & MySQL2024-03-06T16:56:59Zhttps://www.yellowduck.be/posts/rene-roth-composite-indexes-in-laravel-and-mysql<blockquote>
<p>Using indexes/indices (both are correct!) are one of the most obvious ways to speed up database operations in any app
using MySQL and similar databases.</p>
</blockquote>
<p>โ ๏ธ This post links to an external website. โ ๏ธ</p>Pieter Claerhout